Class: Wechat::DataObject

Inherits:
Object
  • Object
show all
Defined in:
lib/wechat/data_object.rb

Direct Known Subclasses

Broadcast, Follower, Media, Menu, Message, Qrcode

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get(method_name, params) ⇒ Hash

Make a HTTP GET request

Parameters:

  • method_name (String)

    The path, relative to Wechat.api_endpoint

  • params (Hash)

    custom params hash

Returns:

  • (Hash)


11
12
13
14
15
16
17
18
# File 'lib/wechat/data_object.rb', line 11

def get(method_name, params)

  if params.empty?
    self.new.request 'get', method_name, params
  else
    self.new.request 'get', [method_name + '?', parameterize_params(params)].join("&"), {}
  end
end

.parameterize_params(params) ⇒ String

Custom Parameterizer for Wechat

Parameters:

  • params (Hash)

    custom params hash

Returns:

  • (String)

    key => value is returned as key=value



35
36
37
# File 'lib/wechat/data_object.rb', line 35

def parameterize_params(params)
  params.inject(""){|string, (k, v)| string << "#{k}=#{v}"; string << "&"; string}[0..-2]
end

.post(method_name, params) ⇒ Hash

Make a HTTP POST request

Parameters:

  • method_name (String)

    The path, relative to Wechat.api_endpoint

  • params (Hash)

    custom params hash

Returns:

  • (Hash)


25
26
27
# File 'lib/wechat/data_object.rb', line 25

def post(method_name, params)
  self.new.request 'post', method_name, params
end

Instance Method Details

#request(http_verb, method_name, params) ⇒ Hash

Make a HTTP request

Parameters:

  • http_verb (String)

    Http method

  • method_name (String)

    The path, relative to Wechat.api_endpoint

  • params (Hash)

    custom params hash

Returns:

  • (Hash)


46
47
48
49
# File 'lib/wechat/data_object.rb', line 46

def request(http_verb, method_name, params)
  response = Wechat::Request.new(http_verb, method_name, params).send_request
  #hashiefy(response)
end