baidu-sms 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/baidu-sms.rb +9 -0
- data/lib/baidu-sms/core.rb +29 -0
- data/lib/baidu-sms/device.rb +13 -0
- data/lib/baidu-sms/level_of_details.rb +17 -0
- data/lib/baidu-sms/report_service.rb +40 -0
- data/lib/baidu-sms/reports.rb +19 -0
- data/lib/baidu-sms/version.rb +3 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 467956a341609a3efc3097829b0d6e73e5477000
|
4
|
+
data.tar.gz: d25a8d79594572a236f926d9546d14e92894b6e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5286357283500638e14684c7e4af00959e16a9bb4b767bdf90dea09b780ab038f1b6096070ee19daa557ccb3fbf704f566ef4cfd048d2cbcac601b1f4b1dfd19
|
7
|
+
data.tar.gz: 7f812d56c67aa4ed755496b45b4bdb56de5eb993dadca0dfe80fdd449a094a7c59f172255626f0b31ae3f2da9506d2b963e533e976e750b1601208186fde448b
|
data/lib/baidu-sms.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require_relative 'baidu-sms/core'
|
2
|
+
require_relative 'baidu-sms/report_service'
|
3
|
+
require_relative 'baidu-sms/reports'
|
4
|
+
require_relative 'baidu-sms/level_of_details'
|
5
|
+
require_relative 'baidu-sms/device'
|
6
|
+
require_relative 'baidu-sms/version'
|
7
|
+
|
8
|
+
module BaiduSMS
|
9
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module BaiduSMS
|
2
|
+
module Core
|
3
|
+
|
4
|
+
BAIDU_HOST = { basic: "http://api.baidu.com", secure: "https://api.baidu.com" }
|
5
|
+
SMS_RESOURCE = "/sem/sms/v3/"
|
6
|
+
COMMON_RESOURCE = "/sem/common/v2"
|
7
|
+
AUTH_NS = "ns2"
|
8
|
+
|
9
|
+
def authorise_headers(username, password, token)
|
10
|
+
{ auth_namespace('AuthHeader') => { auth_namespace('username') => username,
|
11
|
+
auth_namespace('password') => password,
|
12
|
+
auth_namespace('token') => token } }
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialise_client(service, credentials)
|
16
|
+
wsdl_namespace_location = BAIDU_HOST[:secure] + SMS_RESOURCE + service + "?wsdl"
|
17
|
+
authorise_namespace_location = BAIDU_HOST[:basic] + COMMON_RESOURCE
|
18
|
+
Savon.client(wsdl: wsdl_namespace_location,
|
19
|
+
namespaces: { "xmlns:#{AUTH_NS}" => authorise_namespace_location },
|
20
|
+
soap_header: authorise_headers(credentials[:username], credentials[:password], credentials[:token])
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def auth_namespace(str)
|
25
|
+
"#{AUTH_NS}:#{str}"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module BaiduSMS
|
2
|
+
module LevelOfDetails
|
3
|
+
|
4
|
+
ACCOUNT = 2
|
5
|
+
CAMPAIGN = 3
|
6
|
+
AD_GROUP = 5
|
7
|
+
KEYWORD = 6
|
8
|
+
CREATIVE = 7
|
9
|
+
KEYWORD_KEYWORD_ID = 11
|
10
|
+
KEYWORD_PLUS_CREATIVE = 12
|
11
|
+
|
12
|
+
def self.from_name(str)
|
13
|
+
self.const_get(str.upcase)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module BaiduSMS
|
2
|
+
class ReportService
|
3
|
+
include BaiduSMS::Core
|
4
|
+
|
5
|
+
REPORT_SERVICE = "ReportService"
|
6
|
+
|
7
|
+
def initialize(credentials)
|
8
|
+
@client = initialise_client(REPORT_SERVICE, credentials)
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_report(report, params)
|
12
|
+
message = { reportRequestType: params.merge({reportType: report}) }
|
13
|
+
|
14
|
+
response = call(:get_professional_report_id, message: message)
|
15
|
+
response.body[:get_professional_report_id_response][:report_id]
|
16
|
+
end
|
17
|
+
|
18
|
+
def report_ready?(report_id)
|
19
|
+
response = call(:get_report_state, message: { report_id: report_id })
|
20
|
+
response.body[:get_report_state_response][:is_generated].to_i == 3
|
21
|
+
end
|
22
|
+
|
23
|
+
def report_url(report_id)
|
24
|
+
response = call(:get_report_file_url, message: { report_id: report_id })
|
25
|
+
response.body[:get_report_file_url_response][:report_file_path]
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def call(*args)
|
31
|
+
response = @client.call(*args)
|
32
|
+
# debugger
|
33
|
+
header = response.header[:res_header]
|
34
|
+
raise BaiduSMSInvalidRequestError.new("#{header[:failures][:code]} - #{header[:failures][:message]}") unless header[:status].to_i == 0
|
35
|
+
response
|
36
|
+
end
|
37
|
+
|
38
|
+
class BaiduSMSInvalidRequestError < StandardError; end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module BaiduSMS
|
2
|
+
module Reports
|
3
|
+
|
4
|
+
ACCOUNTS = 2
|
5
|
+
CAMPAIGN = 10
|
6
|
+
AD_GROUP = 11
|
7
|
+
KEYWORD = 14
|
8
|
+
CREATIVE = 12
|
9
|
+
KEYWORDS = 9
|
10
|
+
LOCATION = 3
|
11
|
+
SEARCH_TERM = 6
|
12
|
+
MATCHING = 15
|
13
|
+
|
14
|
+
def self.from_name(str)
|
15
|
+
self.const_get(str.upcase)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: baidu-sms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Borkowski
|
8
|
+
- Daniel Padden
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: savon
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: debugger
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
description: Baidu Search Marketing Service API
|
43
|
+
email:
|
44
|
+
- robert.borkowski@forward3d.com
|
45
|
+
- daniel.padden@forward3d.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- lib/baidu-sms.rb
|
51
|
+
- lib/baidu-sms/core.rb
|
52
|
+
- lib/baidu-sms/report_service.rb
|
53
|
+
- lib/baidu-sms/reports.rb
|
54
|
+
- lib/baidu-sms/level_of_details.rb
|
55
|
+
- lib/baidu-sms/device.rb
|
56
|
+
- lib/baidu-sms/version.rb
|
57
|
+
homepage: ''
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.1.5
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Wrapper for connecting to the Baidu Search Marketing API
|
81
|
+
test_files: []
|
82
|
+
has_rdoc:
|