Class: Yclients::Api::Client
- Inherits:
-
Object
- Object
- Yclients::Api::Client
- Defined in:
- lib/yclients/api/client.rb
Constant Summary
Constants included from Companies
Yclients::Api::Companies::URL1, Yclients::Api::Companies::URL2
Constants included from Auth
Instance Attribute Summary collapse
-
#login ⇒ Object
Returns the value of attribute login.
-
#partner_token ⇒ Object
Returns the value of attribute partner_token.
-
#password ⇒ Object
Returns the value of attribute password.
-
#user_token ⇒ Object
Returns the value of attribute user_token.
Instance Method Summary collapse
- #has_user_token? ⇒ Boolean
- #headers(args = {auth: false}) ⇒ Object
-
#initialize(args = {}) ⇒ Client
constructor
A new instance of Client.
- #query_param(key, value, type) ⇒ Object
Methods included from Companies
Methods included from Auth
Constructor Details
#initialize(args = {}) ⇒ Client
8 9 10 11 12 13 |
# File 'lib/yclients/api/client.rb', line 8 def initialize(args={}) @partner_token = args[:partner_token] or raise NoPartnerToken @user_token = args[:user_token] @login = args[:login] @password = args[:password] end |
Instance Attribute Details
#login ⇒ Object
Returns the value of attribute login.
6 7 8 |
# File 'lib/yclients/api/client.rb', line 6 def login @login end |
#partner_token ⇒ Object
Returns the value of attribute partner_token.
6 7 8 |
# File 'lib/yclients/api/client.rb', line 6 def partner_token @partner_token end |
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/yclients/api/client.rb', line 6 def password @password end |
#user_token ⇒ Object
Returns the value of attribute user_token.
6 7 8 |
# File 'lib/yclients/api/client.rb', line 6 def user_token @user_token end |
Instance Method Details
#has_user_token? ⇒ Boolean
15 16 17 |
# File 'lib/yclients/api/client.rb', line 15 def has_user_token? !!@user_token end |
#headers(args = {auth: false}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/yclients/api/client.rb', line 46 def headers(args={auth: false}) if args[:auth] { 'Authorization' => "Bearer #{@partner_token}, User #{@user_token}", "Content-Type" => 'application/json' } else { 'Authorization' => "Bearer #{@partner_token}", "Content-Type" => 'application/json' } end end |
#query_param(key, value, type) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/yclients/api/client.rb', line 19 def query_param(key, value, type) case type when :numeric if value.respond_to?(:to_i) && value.to_i > 0 { key => value } else {} end when :boolean if value == true { key => 1 } elsif value == false { key => 0 } else {} end when :string if value.kind_of?(String) && value.length > 0 { key => value } else {} end else {} end end |