Class: Feathr::Client
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #api_token_auth ⇒ Object
- #api_token_refresh ⇒ Object
- #api_token_verify ⇒ Object
- #auth_headers ⇒ Object
- #auth_token ⇒ Object
- #authenticate! ⇒ Object
- #cashouts ⇒ Object
- #contractors ⇒ Object
- #default_headers ⇒ Object
- #featured_platforms ⇒ Object
- #fetch_from_cache! ⇒ Object
- #incomes ⇒ Object
-
#initialize(config: Feathr::Config.default) ⇒ Client
constructor
A new instance of Client.
- #invoices ⇒ Object
- #managers ⇒ Object
- #memberships ⇒ Object
- #platforms ⇒ Object
- #rebates ⇒ Object
- #receiveables ⇒ Object
- #refresh_token! ⇒ Object
- #request(method: :get, path:, query: {}, headers: {}) ⇒ Object
- #reset_password ⇒ Object
- #users ⇒ Object
- #verify_token! ⇒ Object
Constructor Details
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/feathr/client.rb', line 7 def config @config end |
Class Method Details
Instance Method Details
#api_token_auth ⇒ Object
80 81 82 |
# File 'lib/feathr/client.rb', line 80 def api_token_auth @api_token_auth ||= Feathr::Api::ApiTokenAuth.new(client: self) end |
#api_token_refresh ⇒ Object
84 85 86 |
# File 'lib/feathr/client.rb', line 84 def api_token_refresh @api_token_refresh ||= Feathr::Api::ApiTokenRefresh.new(client: self) end |
#api_token_verify ⇒ Object
88 89 90 |
# File 'lib/feathr/client.rb', line 88 def api_token_verify @api_token_verify ||= Feathr::Api::ApiTokenVerify.new(client: self) end |
#auth_headers ⇒ Object
21 22 23 |
# File 'lib/feathr/client.rb', line 21 def auth_headers { Authorization: "Bearer #{ auth_token }" } end |
#auth_token ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/feathr/client.rb', line 25 def auth_token @auth_token ||= if defined?(Rails) fetch_from_cache! else authenticate! end end |
#authenticate! ⇒ Object
33 34 35 36 37 38 |
# File 'lib/feathr/client.rb', line 33 def authenticate! @auth_token = api_token_auth.authenticate( email: config.api_email, password: config.api_password )['token'] end |
#cashouts ⇒ Object
96 97 98 |
# File 'lib/feathr/client.rb', line 96 def cashouts @cashouts ||= Feathr::Api::Cashouts.new(client: self) end |
#contractors ⇒ Object
112 113 114 |
# File 'lib/feathr/client.rb', line 112 def contractors @contractors ||= Feathr::Api::Contractors.new(client: self) end |
#default_headers ⇒ Object
17 18 19 |
# File 'lib/feathr/client.rb', line 17 def default_headers { 'Content-Type' => 'application/json' } end |
#featured_platforms ⇒ Object
128 129 130 |
# File 'lib/feathr/client.rb', line 128 def featured_platforms @featured_platforms ||= Feathr::Api::FeaturedPlatforms.new(client: self) end |
#fetch_from_cache! ⇒ Object
48 49 50 |
# File 'lib/feathr/client.rb', line 48 def fetch_from_cache! Rails.cache.fetch('qwil_api_token', expires_in: 24.hours) { authenticate! } end |
#incomes ⇒ Object
116 117 118 |
# File 'lib/feathr/client.rb', line 116 def incomes @incomes ||= Feathr::Api::Incomes.new(client: self) end |
#invoices ⇒ Object
136 137 138 |
# File 'lib/feathr/client.rb', line 136 def invoices @invoices ||= Feathr::Api::Invoices.new(client: self) end |
#managers ⇒ Object
100 101 102 |
# File 'lib/feathr/client.rb', line 100 def managers @managers ||= Feathr::Api::Managers.new(client: self) end |
#memberships ⇒ Object
104 105 106 |
# File 'lib/feathr/client.rb', line 104 def memberships @memberships ||= Feathr::Api::Memberships.new(client: self) end |
#platforms ⇒ Object
108 109 110 |
# File 'lib/feathr/client.rb', line 108 def platforms @platforms ||= Feathr::Api::Platforms.new(client: self) end |
#rebates ⇒ Object
120 121 122 |
# File 'lib/feathr/client.rb', line 120 def rebates @rebates ||= Feathr::Api::Rebates.new(client: self) end |
#receiveables ⇒ Object
124 125 126 |
# File 'lib/feathr/client.rb', line 124 def receiveables @receiveables ||= Feathr::Api::Receiveables.new(client: self) end |
#refresh_token! ⇒ Object
40 41 42 |
# File 'lib/feathr/client.rb', line 40 def refresh_token! @auth_token = api_token_refresh.refresh!(auth_token)['token'] end |
#request(method: :get, path:, query: {}, headers: {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/feathr/client.rb', line 52 def request(method: :get, path:, query: {}, headers: {}) url = [config.base_url, path].join('/') unless path == Feathr::Api::ApiTokenAuth.new.api_path headers = default_headers.merge(auth_headers).merge(headers) query = query.to_json end response = self.class.send( method, url, body: query, headers: headers ) if response.success? && block_given? yield response.parsed_response elsif response.success? response.parsed_response else raise Feathr::Api::FeathrError.new( status: response.code, errors: response.parsed_response) end end |
#reset_password ⇒ Object
92 93 94 |
# File 'lib/feathr/client.rb', line 92 def reset_password @reset_password ||= Feathr::Api::ResetPassword.new(client: self) end |
#users ⇒ Object
144 145 146 |
# File 'lib/feathr/client.rb', line 144 def users @users ||= Feathr::Api::Users.new(client: self) end |
#verify_token! ⇒ Object
44 45 46 |
# File 'lib/feathr/client.rb', line 44 def verify_token! api_token_verify.verify(auth_token) end |