Class: Wework::Api::Base
- Inherits:
-
Object
- Object
- Wework::Api::Base
- Includes:
- Methods::Batch, Methods::Crm, Methods::Department, Methods::Media, Methods::Tag, Methods::User
- Defined in:
- lib/wework/api/base.rb
Instance Attribute Summary collapse
-
#corp_id ⇒ Object
Returns the value of attribute corp_id.
-
#options ⇒ Object
Returns the value of attribute options.
-
#secret ⇒ Object
Returns the value of attribute secret.
Instance Method Summary collapse
- #access_token ⇒ Object
- #get(path, headers = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #post(path, payload, headers = {}) ⇒ Object
- #post_file(path, file, headers = {}) ⇒ Object
- #request ⇒ Object
- #valid? ⇒ Boolean
Methods included from Methods::Batch
#batch_getresult, #batch_invite, #batch_replaceparty, #batch_replaceuser, #batch_syncuser
Methods included from Methods::Crm
Methods included from Methods::Tag
#tag_addtagusers, #tag_create, #tag_delete, #tag_deltagusers, #tag_get, #tag_list, #tag_update
Methods included from Methods::Department
#department_create, #department_delete, #department_list, #department_update
Methods included from Methods::User
#authsucc, #convert_to_openid, #convert_to_userid, #user_batchdelete, #user_create, #user_delete, #user_get, #user_list, #user_simplelist, #user_update
Methods included from Methods::Media
#get_media_url, #media_get, #media_upload
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
16 17 18 19 20 21 |
# File 'lib/wework/api/base.rb', line 16 def initialize ={} @corp_id = .delete(:corp_id) @secret = .delete(:secret) @token_store = .delete(:token_store) @options = end |
Instance Attribute Details
#corp_id ⇒ Object
Returns the value of attribute corp_id.
14 15 16 |
# File 'lib/wework/api/base.rb', line 14 def corp_id @corp_id end |
#options ⇒ Object
Returns the value of attribute options.
14 15 16 |
# File 'lib/wework/api/base.rb', line 14 def @options end |
#secret ⇒ Object
Returns the value of attribute secret.
14 15 16 |
# File 'lib/wework/api/base.rb', line 14 def secret @secret end |
Instance Method Details
#access_token ⇒ Object
55 56 57 |
# File 'lib/wework/api/base.rb', line 55 def access_token token_store.token end |
#get(path, headers = {}) ⇒ Object
37 38 39 40 41 |
# File 'lib/wework/api/base.rb', line 37 def get(path, headers = {}) with_token(headers[:params]) do |params| request.get path, headers.merge(params: params) end end |
#post(path, payload, headers = {}) ⇒ Object
43 44 45 46 47 |
# File 'lib/wework/api/base.rb', line 43 def post(path, payload, headers = {}) with_token(headers[:params]) do |params| request.post path, payload, headers.merge(params: params) end end |
#post_file(path, file, headers = {}) ⇒ Object
49 50 51 52 53 |
# File 'lib/wework/api/base.rb', line 49 def post_file(path, file, headers = {}) with_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 |
#valid? ⇒ Boolean
27 28 29 30 31 32 33 34 35 |
# File 'lib/wework/api/base.rb', line 27 def valid? return false if corp_id.nil? token_store.token.present? rescue AccessTokenExpiredError false rescue => e Rails.logger.error "[WEWORK] (valid?) fetch access token error(#{corp_id}): #{e.inspect}" if defined?(Rails) false end |