Sha256: 25d0448d26f89d71e88d3bab8c012d02716ac467dc437d5bd6c9dba5488f994a

Contents?: true

Size: 1.12 KB

Versions: 10

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

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

10 entries across 10 versions & 1 rubygems

Version Path
hackerone-client-0.23.0 lib/hackerone/client/swag.rb
hackerone-client-0.22.1 lib/hackerone/client/swag.rb
hackerone-client-0.22.0 lib/hackerone/client/swag.rb
hackerone-client-0.21.0 lib/hackerone/client/swag.rb
hackerone-client-0.20.1 lib/hackerone/client/swag.rb
hackerone-client-0.20.0 lib/hackerone/client/swag.rb
hackerone-client-0.19.0 lib/hackerone/client/swag.rb
hackerone-client-0.18.0 lib/hackerone/client/swag.rb
hackerone-client-0.17.0 lib/hackerone/client/swag.rb
hackerone-client-0.16.0 lib/hackerone/client/swag.rb