Class: PPC::Baidu

Inherits:
Object
  • Object
show all
Includes:
PPC
Defined in:
lib/ppc/baidu.rb,
lib/ppc/baidu/key.rb,
lib/ppc/baidu/bulk.rb,
lib/ppc/baidu/plan.rb,
lib/ppc/baidu/group.rb,
lib/ppc/baidu/report.rb,
lib/ppc/baidu/account.rb

Direct Known Subclasses

Account, Bulk, Group, Key, Plan, Report

Defined Under Namespace

Classes: Account, Bulk, BulkException, Group, Key, Plan, Report, ReportException

Constant Summary

Constants included from PPC

VERSION

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Baidu

Returns a new instance of Baidu.



16
17
18
19
20
21
22
# File 'lib/ppc/baidu.rb', line 16

def initialize(params = {})
  @service = params[:service] + 'Service'
  @username = params[:username]
  @password = params[:password]
  @token = params[:token]
  @debug = params[:debug] || false
end

Instance Method Details

#operationsObject



46
47
# File 'lib/ppc/baidu.rb', line 46

def operations
end

#request(method, params = {}, with_header = false) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ppc/baidu.rb', line 25

def request(method,params = {}, with_header = false)
  uri = URI("https://api.baidu.com/json/sms/v3/#{@service}/#{method}")
  http_body = {
    header: request_header,
    body: params
  }.to_json

  http_header = {
    'Content-Type' => 'application/json; charset=UTF-8'
  }

  http = Net::HTTP.new(uri.host, 443)
  http.set_debug_output $stderr
  http.use_ssl = true

  response = http.post(uri.path, http_body, http_header)
  response =  (JSON.parse response.body)
  # if not needed, only return body
  return response['body'] unless with_header else response
end