comscore_ruby 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +81 -0
- data/lib/comscore_ruby/client.rb +7 -2
- data/lib/comscore_ruby/version.rb +1 -1
- data/test/client_test.rb +1 -2
- metadata +8 -5
data/README.markdown
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# comscore_ruby
|
2
|
+
|
3
|
+
## what is it
|
4
|
+
comscore_ruby is a minimal Ruby wrapper to [comScore's SOAP API](https://api.comscore.com). It follows a design policy similar to that of [sucker](https://rubygems.org/gems/sucker) built for Amazon's API.
|
5
|
+
|
6
|
+
comScore's API is closed, you have to be a paying customer in order to access the data.
|
7
|
+
|
8
|
+
## installation
|
9
|
+
[sudo] gem install comscore_ruby
|
10
|
+
|
11
|
+
## initialization and authentication
|
12
|
+
comScore uses basic HTTP authentication so just provide your regular login details.
|
13
|
+
|
14
|
+
client = ComScore::Client.new(
|
15
|
+
username,
|
16
|
+
password,
|
17
|
+
:log => false,
|
18
|
+
:wait_time => 1
|
19
|
+
)
|
20
|
+
|
21
|
+
## usage
|
22
|
+
There are only two core methods for the client which doesn't try to "over architect a spaghetti API":
|
23
|
+
|
24
|
+
* `get_report` - used to...while get reports and
|
25
|
+
* `request` - more generic used to make any kind of request
|
26
|
+
|
27
|
+
For reference, I'd recommend keeping [comScore's SOAP API](https://api.comscore.com) open as you code to understand what services you have available to you. Also ask them for their initial documentation which is absolutely horrible but at least their engineering staff is pretty helpful.
|
28
|
+
|
29
|
+
The response returned by either of these requests is actually a [savon](http://savonrb.com/) [request object](http://rubydoc.info/gems/savon/0.9.7/Savon/Client#request-instance_method) to allow for maximum flexibility. You can do things with this that are particularly nice:
|
30
|
+
|
31
|
+
* `response.to_hash` which works well in most cases but has been known to be buggy with XML attributes (at least in Ruby 1.8.x)
|
32
|
+
* `response.doc` the Nokogiri XML document to allow for some pretty advanced XPATH
|
33
|
+
|
34
|
+
9x out of 10 you'll be able to use to_hash on a response but you will sometimes have need to query with XPATH due to how `to_hash` parses certain XML attributes in comScore's results.
|
35
|
+
|
36
|
+
## examples
|
37
|
+
# Find all media within the Canadian dictionary (from 2 months ago) that match "The Globe And Mail"
|
38
|
+
client.request(:key_measures, :fetch_media) do |xml|
|
39
|
+
xml.parameterId("media")
|
40
|
+
xml.fetchMediaQuery("xmlns" => "http://comscore.com/FetchMedia") {
|
41
|
+
xml.SearchCritera(:ExactMatch => "false", :Critera => "The Globe And Mail")
|
42
|
+
}
|
43
|
+
xml.reportQuery("xmlns" => "http://comscore.com/ReportQuery") {
|
44
|
+
xml.Parameter(:KeyId => "geo", :Value => ComScore::GEOGRAPHIES["Canada"])
|
45
|
+
xml.Parameter(:KeyId => "loc", :Value => ComScore::LOCATIONS["Home and Work"])
|
46
|
+
xml.Parameter(:KeyId => "timeType", :Value => ComScore::TIME_TYPES["Months"])
|
47
|
+
xml.Parameter(:KeyId => "timePeriod", :Value => DateTime.now.to_date.to_comscore_time_period - 2)
|
48
|
+
xml.Parameter(:KeyId => "mediaSetType", :Value => ComScore::MEDIA_SET_TYPES["Ranked Categories"])
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
# Find all the categories (or media sets) within the Canadian dictionary (from 2 months ago)
|
53
|
+
client.request(:key_measures, :discover_parameter_values) do |xml|
|
54
|
+
xml.parameterId("mediaSet")
|
55
|
+
xml.query(:xmlns => "http://comscore.com/ReportQuery") {
|
56
|
+
xml.Parameter(:KeyId => "geo", :Value => ComScore::GEOGRAPHIES["Canada"])
|
57
|
+
xml.Parameter(:KeyId => "timeType", :Value => ComScore::TIME_TYPES["Months"])
|
58
|
+
xml.Parameter(:KeyId => "timePeriod", :Value => DateTime.now.to_date.to_comscore_time_period - 2)
|
59
|
+
xml.Parameter(:KeyId => "mediaSetType", :Value => ComScore::MEDIA_SET_TYPES["Ranked Categories"])
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
# Get a key measures report for the Community - Lifestyles category (778226) for August, 2011
|
64
|
+
client.get_report(:key_measures,
|
65
|
+
:geo => ComScore::GEOGRAPHIES["Canada"],
|
66
|
+
:loc => ComScore::LOCATIONS["Home and Work"],
|
67
|
+
:timeType => ComScore::TIME_TYPES["Months"],
|
68
|
+
:timePeriod => Date.new(2011, 8),
|
69
|
+
:mediaSet => 778226,
|
70
|
+
:mediaSetType => ComScore::MEDIA_SET_TYPES["Ranked Categories"],
|
71
|
+
:targetType => ComScore::TARGET_TYPES["Simple"],
|
72
|
+
:targetGroup => ComScore::TARGET_GROUPS["Total Audience"],
|
73
|
+
:measure => [ComScore::MEASURES["Total Unique Visitors (000)"]]
|
74
|
+
)
|
75
|
+
|
76
|
+
## todo
|
77
|
+
* More support for other parameters: geographies, locations etc. I'm Canadian, so I really only built it for the parameters I use and know of.
|
78
|
+
* Passing of a hash to the initializer for config options including username and password so you don't have to awkwardly set logging off after initialization.
|
79
|
+
|
80
|
+
## see also
|
81
|
+
My other client library [romniture](https://github.com/msukmanowsky/ROmniture) for those of you looking to pull data from Omniture as well.
|
data/lib/comscore_ruby/client.rb
CHANGED
@@ -18,8 +18,13 @@ module ComScore
|
|
18
18
|
:mobilens_trend => {:wsdl => "#{BASE_URI}MobiLens/Trend.asmx?WSDL"}
|
19
19
|
}
|
20
20
|
|
21
|
-
def initialize(
|
22
|
-
@username
|
21
|
+
def initialize(username, password, options={})
|
22
|
+
@username = username
|
23
|
+
@password = password
|
24
|
+
@wait_time = options[:wait_time] ? options[:wait_time] : DEFAULT_REPORT_WAIT_TIME
|
25
|
+
self.log = options[:log] ? options[:log] : false
|
26
|
+
|
27
|
+
|
23
28
|
@client = Savon::Client.new
|
24
29
|
@client.http.auth.basic(@username, @password)
|
25
30
|
end
|
data/test/client_test.rb
CHANGED
@@ -9,8 +9,7 @@ class ClientTest < Test::Unit::TestCase
|
|
9
9
|
def setup
|
10
10
|
@config = YAML::load(File.open("test/config.yml"))["comscore"]
|
11
11
|
|
12
|
-
@client = ComScore::Client.new(@config["username"], @config["password"])
|
13
|
-
@client.log = false
|
12
|
+
@client = ComScore::Client.new(@config["username"], @config["password"], :log => false, :wait_time => 1)
|
14
13
|
end
|
15
14
|
|
16
15
|
def test_fetch_media
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comscore_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 53
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 21
|
10
|
+
version: 0.0.21
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mike Sukmanowsky
|
@@ -15,7 +15,8 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-18 00:00:00 -04:00
|
19
|
+
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: savon
|
@@ -59,6 +60,7 @@ extra_rdoc_files: []
|
|
59
60
|
files:
|
60
61
|
- .gitignore
|
61
62
|
- Gemfile
|
63
|
+
- README.markdown
|
62
64
|
- Rakefile
|
63
65
|
- comscore_ruby.gemspec
|
64
66
|
- lib/comscore_ruby.rb
|
@@ -67,6 +69,7 @@ files:
|
|
67
69
|
- lib/comscore_ruby/core_ext/date.rb
|
68
70
|
- lib/comscore_ruby/version.rb
|
69
71
|
- test/client_test.rb
|
72
|
+
has_rdoc: true
|
70
73
|
homepage: https://github.com/msukmanowsky/comscore_ruby/wiki
|
71
74
|
licenses: []
|
72
75
|
|
@@ -96,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
99
|
requirements: []
|
97
100
|
|
98
101
|
rubyforge_project: comscore_ruby
|
99
|
-
rubygems_version: 1.
|
102
|
+
rubygems_version: 1.5.0
|
100
103
|
signing_key:
|
101
104
|
specification_version: 3
|
102
105
|
summary: Use comScore's SOAP API in a manner that does not require you to bang your head against a wall.
|