Class: Wework::Api::Base
- Inherits:
-
Object
- Object
- Wework::Api::Base
- Includes:
- Cipher
- Defined in:
- lib/wework/api/base.rb
Constant Summary
Constants included from Cipher
Cipher::BLOCK_SIZE, Cipher::CIPHER
Instance Attribute Summary collapse
-
#app_id ⇒ Object
readonly
Returns the value of attribute app_id.
-
#app_secret ⇒ Object
readonly
Returns the value of attribute app_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, app_id, app_secret, options = {}) ⇒ Base
constructor
A new instance of Base.
- #media_get(media_id) ⇒ Object
-
#media_upload(type, file) ⇒ Object
public API.
- #post(path, payload, headers = {}) ⇒ Object
- #post_file(path, file, headers = {}) ⇒ Object
- #request ⇒ Object
- #valid? ⇒ Boolean
Methods included from Cipher
#decrypt, #encrypt, #pack, #unpack
Constructor Details
#initialize(corp_id, app_id, app_secret, options = {}) ⇒ Base
Returns a new instance of Base.
18 19 20 21 22 23 |
# File 'lib/wework/api/base.rb', line 18 def initialize(corp_id, app_id, app_secret, ={}) @corp_id = corp_id @app_id = app_id @app_secret = app_secret @options = end |
Instance Attribute Details
#app_id ⇒ Object (readonly)
Returns the value of attribute app_id.
12 13 14 |
# File 'lib/wework/api/base.rb', line 12 def app_id @app_id end |
#app_secret ⇒ Object (readonly)
Returns the value of attribute app_secret.
12 13 14 |
# File 'lib/wework/api/base.rb', line 12 def app_secret @app_secret end |
#corp_id ⇒ Object (readonly)
Returns the value of attribute corp_id.
12 13 14 |
# File 'lib/wework/api/base.rb', line 12 def corp_id @corp_id end |
#options ⇒ Object
Returns the value of attribute options.
13 14 15 |
# File 'lib/wework/api/base.rb', line 13 def @options end |
Instance Method Details
#get(path, headers = {}) ⇒ Object
38 39 40 41 42 |
# File 'lib/wework/api/base.rb', line 38 def get(path, headers = {}) with_access_token(headers[:params]) do |params| request.get path, headers.merge(params: params) end end |
#media_get(media_id) ⇒ Object
61 62 63 |
# File 'lib/wework/api/base.rb', line 61 def media_get(media_id) get 'media/get', params: { media_id: media_id }, as: :file end |
#media_upload(type, file) ⇒ Object
public API
57 58 59 |
# File 'lib/wework/api/base.rb', line 57 def media_upload type, file post_file 'media/upload', file, params: { type: type } end |
#post(path, payload, headers = {}) ⇒ Object
44 45 46 47 48 |
# File 'lib/wework/api/base.rb', line 44 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
50 51 52 53 54 |
# File 'lib/wework/api/base.rb', line 50 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
25 26 27 |
# File 'lib/wework/api/base.rb', line 25 def request @request ||= Wework::Request.new(API_ENDPOINT, false) end |
#valid? ⇒ Boolean
29 30 31 32 33 34 35 36 |
# File 'lib/wework/api/base.rb', line 29 def valid? access_token.present? rescue AccessTokenExpiredError false rescue => e Rails.logger.error "[WEWORK] (valid?) fetch access token error(#{corp_id}##{app_id}): #{e.inspect}" if defined?(Rails) false end |