Class: Teespring::Client
- Inherits:
-
Object
- Object
- Teespring::Client
- Defined in:
- lib/teespring/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
Instance Method Summary collapse
- #authenticate(email, password) ⇒ Object
- #campaigns(search = nil, states = nil) ⇒ Object
- #connection ⇒ Object
- #get(url, params) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #me ⇒ Object
- #post(url, params) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/teespring/client.rb', line 8 def initialize( = {}) @app_id = .delete(:app_id) end |
Instance Attribute Details
#access_token ⇒ Object
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 |
#connection ⇒ Object
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 |
#me ⇒ Object
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 |
#reset ⇒ Object
16 17 18 |
# File 'lib/teespring/client.rb', line 16 def reset @connection = nil end |