Class: Wework::Api::Base

Inherits:
Object
  • Object
show all
Includes:
Cipher
Defined in:
lib/wework/api/base.rb

Direct Known Subclasses

Agent, Contact

Constant Summary

Constants included from Cipher

Cipher::BLOCK_SIZE, Cipher::CIPHER

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
  @corp_id      = corp_id
  @app_id       = app_id
  @app_secret   = app_secret
  @options      = options
end

Instance Attribute Details

#app_idObject (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_secretObject (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_idObject (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

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/wework/api/base.rb', line 13

def options
  @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

#requestObject



25
26
27
# File 'lib/wework/api/base.rb', line 25

def request
  @request ||= Wework::Request.new(API_ENDPOINT, false)
end

#valid?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/wework/api/base.rb', line 29

def valid?
  access_token.present?
rescue AccessTokenExpiredError
  false
end