Sha256: 70cfcec632604ed07d4b4b0a7edb104a270c8b92105252cb58e753290f39af2d

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

module TophatterMerchant
  class Account < Resource
    attr_accessor :access_token, :first_name, :last_name, :store_name, :email, :country, :time_zone

    def id
      email
    end

    class << self
      # ap TophatterMerchant::Account.schema
      def schema
        get(url: "#{path}/schema.json")
      end

      # ap TophatterMerchant::Account.authenticate(email: 'megatron@autobot.com', password: 'ipipip').to_h
      def authenticate(email:, password:)
        Account.new post(url: "#{path}/authenticate.json", params: { email: email, password: password })
      end

      # ap TophatterMerchant::Account.me.to_h
      def me
        Account.new get(url: "#{path}/me.json")
      end

      # ap TophatterMerchant::Account.create(first_name: 'Foo', last_name: 'Bar', store_name: 'Foo Bar, Inc', email: 'foo@bar.com', password: 'ipipip', country: 'United States', time_zone: 'Pacific Time (US & Canada)').to_h
      def create(data)
        Account.new post(url: "#{path}.json", params: data)
      end

      # Change first & last name:
      # ap TophatterMerchant::Account.update(first_name: 'Mega', last_name: 'Tron').to_h
      # Change password:
      # ap TophatterMerchant::Account.update(password: 'qwer1234').to_h
      # ap TophatterMerchant::Account.authenticate(email: 'megatron@autobot.com', password: 'qwer1234').to_h
      # ap TophatterMerchant::Account.update(password: 'ipipip').to_h
      def update(data)
        Account.new post(url: "#{path}/update.json", params: data)
      end

      protected

      def path
        super + '/account'
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tophatter-merchant-1.1.3 lib/tophatter_merchant/account.rb
tophatter-merchant-1.1.2 lib/tophatter_merchant/account.rb
tophatter-merchant-1.1.1 lib/tophatter_merchant/account.rb