Class: Wework::Api::Base

Inherits:
Object
  • Object
show all
Includes:
Methods::Batch, Methods::Crm, Methods::Department, Methods::Media, Methods::Tag, Methods::User
Defined in:
lib/wework/api/base.rb

Direct Known Subclasses

Agent, Contact, Corp, Provider, Suite

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Methods::Batch

#batch_getresult, #batch_invite, #batch_replaceparty, #batch_replaceuser, #batch_syncuser

Methods included from Methods::Crm

#crm_get_external_contact

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, #simple_list

Methods included from Methods::User

#authsucc, #convert_to_openid, #convert_to_userid, #user_batchdelete, #user_create, #user_delete, #user_get, #user_getuserid, #user_list, #user_list_id, #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.



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

def initialize options={}
  @corp_id      = options.delete(:corp_id)
  @secret       = options.delete(:secret)
  @token_store  = options.delete(:token_store)
  @options      = options
end

Instance Attribute Details

#corp_idObject

Returns the value of attribute corp_id.



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

def corp_id
  @corp_id
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#secretObject

Returns the value of attribute secret.



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

def secret
  @secret
end

Instance Method Details

#access_tokenObject



70
71
72
# File 'lib/wework/api/base.rb', line 70

def access_token
  token_store.token
end

#get(path, headers = {}) ⇒ Object



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

def get(path, headers = {})
  with_token(headers[:params]) do |params|
    request.get path, headers.merge(params: params)
  end
end

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



58
59
60
61
62
# File 'lib/wework/api/base.rb', line 58

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



64
65
66
67
68
# File 'lib/wework/api/base.rb', line 64

def post_file(path, file, headers = {})
  with_token(headers[:params]) do |params|
    request.post_file path, file, headers.merge(params: params)
  end
end

#requestObject



38
39
40
# File 'lib/wework/api/base.rb', line 38

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

#valid?Boolean

Returns:

  • (Boolean)


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

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