Class: Wechat::Api::Base

Inherits:
Object
  • Object
show all
Defined in:
app/apis/wechat/api/base.rb

Direct Known Subclasses

Platform, Program, Public, Work

Defined Under Namespace

Modules: Datacube, Sns

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Base

Returns a new instance of Base.



7
8
9
10
# File 'app/apis/wechat/api/base.rb', line 7

def initialize(app)
  @app = app
  @client = Wechat::HttpClient.new
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



5
6
7
# File 'app/apis/wechat/api/base.rb', line 5

def app
  @app
end

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'app/apis/wechat/api/base.rb', line 5

def client
  @client
end

Instance Method Details

#get(path, params: {}, headers: {}, base: nil, as: nil) ⇒ Object



12
13
14
15
16
# File 'app/apis/wechat/api/base.rb', line 12

def get(path, params: {}, headers: {}, base: nil, as: nil)
  with_access_token(params) do |with_token_params|
    @client.get path, headers: headers, params: with_token_params, base: base, as: as
  end
end

#post(path, params: {}, headers: {}, base: nil, **payload) ⇒ Object



18
19
20
21
22
# File 'app/apis/wechat/api/base.rb', line 18

def post(path, params: {}, headers: {}, base: nil, **payload)
  with_access_token(params) do |with_token_params|
    @client.post path, payload.to_json, headers: headers, params: with_token_params, base: base
  end
end

#post_file(path, file, params: {}, headers: {}, base: nil) ⇒ Object



24
25
26
27
28
# File 'app/apis/wechat/api/base.rb', line 24

def post_file(path, file, params: {}, headers: {}, base: nil)
  with_access_token(params) do |with_token_params|
    @client.post_file path, file, headers: headers, params: with_token_params, base: base
  end
end