Class: Wework::Api::Base
- Inherits:
-
Object
- Object
- Wework::Api::Base
- Defined in:
- lib/wework/api/base.rb
Instance Attribute Summary collapse
-
#agent_id ⇒ Object
readonly
Returns the value of attribute agent_id.
-
#agent_secret ⇒ Object
readonly
Returns the value of attribute agent_secret.
-
#corp_id ⇒ Object
readonly
Returns the value of attribute corp_id.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #get(path, headers = {}) ⇒ Object
-
#initialize(corp_id, agent_id, agent_secret, options = {}) ⇒ Base
constructor
A new instance of Base.
- #post(path, payload, headers = {}) ⇒ Object
- #post_file(path, file, headers = {}) ⇒ Object
- #request ⇒ Object
- #token_store ⇒ Object
- #with_access_token(params = {}, tries = 2) ⇒ Object
Constructor Details
#initialize(corp_id, agent_id, agent_secret, options = {}) ⇒ Base
Returns a new instance of Base.
12 13 14 15 16 17 |
# File 'lib/wework/api/base.rb', line 12 def initialize(corp_id, agent_id, agent_secret, ={}) @corp_id = corp_id @agent_id = agent_id @agent_secret = agent_secret @options = end |
Instance Attribute Details
#agent_id ⇒ Object (readonly)
Returns the value of attribute agent_id.
7 8 9 |
# File 'lib/wework/api/base.rb', line 7 def agent_id @agent_id end |
#agent_secret ⇒ Object (readonly)
Returns the value of attribute agent_secret.
7 8 9 |
# File 'lib/wework/api/base.rb', line 7 def agent_secret @agent_secret end |
#corp_id ⇒ Object (readonly)
Returns the value of attribute corp_id.
7 8 9 |
# File 'lib/wework/api/base.rb', line 7 def corp_id @corp_id end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/wework/api/base.rb', line 8 def @options end |
Instance Method Details
#get(path, headers = {}) ⇒ Object
27 28 29 30 31 |
# File 'lib/wework/api/base.rb', line 27 def get(path, headers = {}) with_access_token(headers[:params]) do |params| request.get path, headers.merge(params: params) end end |
#post(path, payload, headers = {}) ⇒ Object
33 34 35 36 37 |
# File 'lib/wework/api/base.rb', line 33 def post(path, payload, headers = {}) with_access_token(headers[:params]) do |params| request.post path, payload, headers.merge(params: params) end end |
#post_file(path, file, headers = {}) ⇒ Object
39 40 41 42 43 |
# File 'lib/wework/api/base.rb', line 39 def post_file(path, file, headers = {}) with_access_token(headers[:params]) do |params| request.post_file path, file, headers.merge(params: params) end end |
#request ⇒ Object
23 24 25 |
# File 'lib/wework/api/base.rb', line 23 def request @request ||= Wework::Request.new(API_ENDPOINT, false) end |
#token_store ⇒ Object
19 20 21 |
# File 'lib/wework/api/base.rb', line 19 def token_store @token_store ||= Token::RedisStore.new self end |
#with_access_token(params = {}, tries = 2) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/wework/api/base.rb', line 45 def with_access_token(params = {}, tries = 2) params ||= {} yield(params.merge(access_token: access_token)) rescue AccessTokenExpiredError token_store.refresh_token retry unless (tries -= 1).zero? end |