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
35 36 37 38 39 |
# File 'lib/wework/api/base.rb', line 35 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
58 59 60 |
# File 'lib/wework/api/base.rb', line 58 def media_get(media_id) get 'media/get', params: { media_id: media_id }, as: :file end |
#media_upload(type, file) ⇒ Object
public API
54 55 56 |
# File 'lib/wework/api/base.rb', line 54 def media_upload type, file post_file 'media/upload', file, params: { type: type } end |
#post(path, payload, headers = {}) ⇒ Object
41 42 43 44 45 |
# File 'lib/wework/api/base.rb', line 41 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
47 48 49 50 51 |
# File 'lib/wework/api/base.rb', line 47 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 |
# File 'lib/wework/api/base.rb', line 29 def valid? access_token.present? rescue AccessTokenExpiredError false end |