Sha256: 1ab02cc849f39d0c70e7dc20a4067d24f514c877f7a8092e5eccf02819264149

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

module HackerOne
  module Client
    class Swag
      include ResourceHelper
      delegate :sent, :created_at, to: :attributes

      def initialize(swag, program = nil)
        @swag = swag
        @program = program
      end

      def id
        @swag[:id]
      end

      def sent?
        !!attributes.sent
      end

      def user
        if user_relationship = relationships[:user]
          HackerOne::Client::User.new(user_relationship[:data])
        end
      end

      def address
        if address_relationship = relationships[:address]
          HackerOne::Client::Address.new(address_relationship[:data])
        end
      end

      def mark_as_sent!
        body = {
          type: "swag",
          attributes: {
            sent: true
          }
        }

        response_json = make_put_request("programs/#{@program.id}/swag/#{id}", request_body: body)
        self.class.new(response_json, @program)
      end

      private

      def attributes
        OpenStruct.new(@swag[:attributes])
      end

      def relationships
        @swag[:relationships]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hackerone-client-0.15.0 lib/hackerone/client/swag.rb
hackerone-client-0.14.2 lib/hackerone/client/swag.rb
hackerone-client-0.14.1 lib/hackerone/client/swag.rb
hackerone-client-0.14.0 lib/hackerone/client/swag.rb