Class: Teespring::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/teespring/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



8
9
10
# File 'lib/teespring/client.rb', line 8

def initialize(options = {})
  @app_id = options.delete(:app_id)
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



6
7
8
# File 'lib/teespring/client.rb', line 6

def access_token
  @access_token
end

Instance Method Details

#authenticate(email, password) ⇒ Object



20
21
22
23
24
# File 'lib/teespring/client.rb', line 20

def authenticate(email, password)
  @response = post '/v1/auth-tokens', email: email, password: password, app_id: @app_id

  @access_token = @response.body['token']
end

#campaigns(search = nil, states = nil) ⇒ Object



30
31
32
# File 'lib/teespring/client.rb', line 30

def campaigns(search = nil, states = nil)
  @response = get '/seller/v1/campaigns', { access_token: @access_token, search: search, states: states, page: 1, per_page: 100 }
end

#connectionObject



12
13
14
# File 'lib/teespring/client.rb', line 12

def connection
  @connection ||= ::Faraday.new(url: endpoint)
end

#get(url, params) ⇒ Object



34
35
36
# File 'lib/teespring/client.rb', line 34

def get(url, params)
  request(:get, url, params)
end

#meObject



26
27
28
# File 'lib/teespring/client.rb', line 26

def me
  @response = get '/me', { access_token: @access_token }
end

#post(url, params) ⇒ Object



38
39
40
# File 'lib/teespring/client.rb', line 38

def post(url, params)
  request(:post, url, params)
end

#resetObject



16
17
18
# File 'lib/teespring/client.rb', line 16

def reset
  @connection = nil
end