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



33
34
35
36
37
# File 'lib/wework/api/base.rb', line 33

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



56
57
58
# File 'lib/wework/api/base.rb', line 56

def media_get(media_id)
  get 'media/get', params: { media_id: media_id }, as: :file
end

#media_upload(type, file) ⇒ Object

public API



52
53
54
# File 'lib/wework/api/base.rb', line 52

def media_upload type, file
  post_file 'media/upload', file, params: { type: type }
end

#post(path, payload, headers = {}) ⇒ Object



39
40
41
42
43
# File 'lib/wework/api/base.rb', line 39

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



45
46
47
48
49
# File 'lib/wework/api/base.rb', line 45

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
# File 'lib/wework/api/base.rb', line 29

def valid?
  access_token.present?
end