similarweb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ /.config
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
36
+ >>>>>>> 98e22f4287bbe6149ea46316b9adfd9e36f58684
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in similarweb.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ similarweb (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.3.6)
10
+ coderay (1.1.0)
11
+ crack (0.4.2)
12
+ safe_yaml (~> 1.0.0)
13
+ diff-lcs (1.2.5)
14
+ faraday (0.9.0)
15
+ multipart-post (>= 1.2, < 3)
16
+ method_source (0.8.2)
17
+ multipart-post (2.0.0)
18
+ pry (0.9.12.6)
19
+ coderay (~> 1.0)
20
+ method_source (~> 0.8)
21
+ slop (~> 3.4)
22
+ rake (10.2.2)
23
+ rspec (2.14.1)
24
+ rspec-core (~> 2.14.0)
25
+ rspec-expectations (~> 2.14.0)
26
+ rspec-mocks (~> 2.14.0)
27
+ rspec-core (2.14.8)
28
+ rspec-expectations (2.14.5)
29
+ diff-lcs (>= 1.1.3, < 2.0)
30
+ rspec-mocks (2.14.6)
31
+ safe_yaml (1.0.2)
32
+ slop (3.5.0)
33
+ webmock (1.17.4)
34
+ addressable (>= 2.2.7)
35
+ crack (>= 0.3.2)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ bundler (~> 1.5)
42
+ faraday
43
+ pry
44
+ rake
45
+ rspec
46
+ similarweb!
47
+ webmock
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Steven Lai, John McLaughlin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,153 @@
1
+ <<<<<<< HEAD
2
+ # Similarweb
3
+
4
+ Ruby client for [SimilarWeb API](https://developer.similarweb.com/)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'similarweb'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install similarweb
19
+
20
+ ## Usage
21
+
22
+ ``` ruby
23
+ client = SimilarWeb::Client.new(api_key: key)
24
+ traffic = client.traffic('disney.com')
25
+ ```
26
+
27
+ ### Also Visited
28
+
29
+ Returns a list of websites frequently visited by users of the given domain.
30
+
31
+ ``` ruby
32
+ client = SimilarWeb::Client.new(api_key: key)
33
+ also_visited = client.also_visited('disney.com')
34
+ ```
35
+
36
+ ### Category
37
+
38
+ Will return a domain’s category and its global rank within its given category.
39
+
40
+ ``` ruby
41
+ client = SimilarWeb::Client.new(api_key: key)
42
+ category = client.category('disney.com')
43
+ ```
44
+
45
+ ### Category Rank
46
+
47
+ Will return a domain’s category and its global rank within its given category.
48
+
49
+ ``` ruby
50
+ client = SimilarWeb::Client.new(api_key: key)
51
+ category_rank = client.category_rank('disney.com')
52
+ ```
53
+
54
+ ### Destinations
55
+
56
+ Returns the 10 leading sites that receive direct clicks from the given domain.
57
+
58
+ ``` ruby
59
+ client = SimilarWeb::Client.new(api_key: key)
60
+ destinations = client.destinations('disney.com')
61
+ ```
62
+
63
+ ### Engagement
64
+
65
+ Provides three web engagement metrics: average page views, average time on site and bounce rate.
66
+
67
+ ``` ruby
68
+ client = SimilarWeb::Client.new(api_key: key)
69
+ engagement = client.engagement('disney.com')
70
+ ```
71
+
72
+ ### Estimated Visits
73
+
74
+ Returns the estimated number of visitors per domain.
75
+
76
+ ``` ruby
77
+ client = SimilarWeb::Client.new(api_key: key)
78
+ visits = client.estimated_visits('disney.com')
79
+ ```
80
+
81
+ ### Keywords
82
+
83
+ Access three search metrics: paid/organic search distribution, 10 paid keywords, and 10 organic keywords.
84
+
85
+ ``` ruby
86
+ client = SimilarWeb::Client.new(api_key: key)
87
+ keywords = client.keywords('disney.com')
88
+ ```
89
+
90
+ ### Referrals
91
+
92
+ Returns the 10 leading sites that direct clicks to the given domain.
93
+
94
+ ``` ruby
95
+ client = SimilarWeb::Client.new(api_key: key)
96
+ referrals = client.referrals('disney.com')
97
+ ```
98
+
99
+ ### Similar Sites
100
+
101
+ Input a domain and receive an output of 20 similar websites and their similarity score.
102
+ ``` ruby
103
+ client = SimilarWeb::Client.new(api_key: key)
104
+ similar = client.similar_sites('disney.com')
105
+ ```
106
+
107
+ ### Social Referrals
108
+
109
+ Access the five leading social networks sending traffic to the given domain.
110
+
111
+ ``` ruby
112
+ client = SimilarWeb::Client.new(api_key: key)
113
+ social = client.social_referrals('disney.com')
114
+ ```
115
+
116
+ ### Tags
117
+
118
+ Returns 10 tags per domain based on semantic analysis, meta-data, anchor text and more.
119
+
120
+ ``` ruby
121
+ client = SimilarWeb::Client.new(api_key: key)
122
+ tags = client.tags('disney.com')
123
+ ```
124
+
125
+ ### Traffic
126
+
127
+ Will return four web traffic metrics: global rank, country rank/traffic geography, traffic reach and traffic sources distribution.
128
+
129
+ ``` ruby
130
+ client = SimilarWeb::Client.new(api_key: key)
131
+ traffic = client.traffic('disney.com')
132
+ ```
133
+
134
+ ## Author
135
+ [John McLaughlin](mailto:j@yar.com) & [Steven Lai](mailto:lai.steven@gmail.com)
136
+
137
+ ## Contributing
138
+
139
+ 1. Fork it ( http://github.com/<my-github-username>/similarweb/fork )
140
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
141
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
142
+ 4. Push to the branch (`git push origin my-new-feature`)
143
+ 5. Create new Pull Request
144
+
145
+ ## Copyright
146
+ Copyright (c) 2014 [John McLaughlin](mailto:j@yar.com), [Steven Lai](mailto:lai.steven@gmail.com).
147
+ See [LICENSE][license] for details.
148
+
149
+ [license]: LICENSE.md
150
+ =======
151
+ similarweb
152
+ ==========
153
+ >>>>>>> 98e22f4287bbe6149ea46316b9adfd9e36f58684
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,8 @@
1
+ module Similarweb
2
+ module AlsoVisited
3
+ def also_visited(domain)
4
+ response = self.http_client.get "#{domain}/v2/alsovisited?Format=JSON&UserKey=#{self.api_key}"
5
+ JSON(response.body)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Similarweb
2
+ module Category
3
+ def category(domain)
4
+ response = self.http_client.get "#{domain}/v2/category?Format=JSON&UserKey=#{self.api_key}"
5
+ JSON(response.body)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Similarweb
2
+ module CategoryRank
3
+ def category_rank(domain)
4
+ response = self.http_client.get "#{domain}/v2/CategoryRank?Format=JSON&UserKey=#{self.api_key}"
5
+ JSON(response.body)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,31 @@
1
+ module Similarweb
2
+ class Client
3
+ include AlsoVisited
4
+ include EstimatedVisits
5
+ include SimilarSites
6
+ include CategoryRank
7
+ include Destinations
8
+ include Keywords
9
+ include SocialReferrals
10
+ include Category
11
+ include Engagement
12
+ include Referrals
13
+ include Tags
14
+ include Traffic
15
+ attr_accessor :api_key, :http_client
16
+
17
+ def initialize(args = {})
18
+ args.each do |key, value|
19
+ send(:"#{key}=", value)
20
+ end
21
+ make_http_client!
22
+ end
23
+
24
+ private
25
+
26
+ def make_http_client!
27
+ base_url = "http://api.similarweb.com/Site/"
28
+ self.http_client = Faraday.new(:url => base_url)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ module Similarweb
2
+ module Destinations
3
+ def destinations(domain)
4
+ response = self.http_client.get "#{domain}/v2/leadingdestinationsites?Format=JSON&UserKey=#{self.api_key}"
5
+ JSON(response.body)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Similarweb
2
+ module Engagement
3
+ def engagement(domain)
4
+ response = self.http_client.get "#{domain}/v1/engagement?Format=JSON&UserKey=#{self.api_key}"
5
+ JSON(response.body)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Similarweb
2
+ module EstimatedVisits
3
+ def estimated_visits(domain)
4
+ response = self.http_client.get "#{domain}/v1/EstimatedTraffic?Format=JSON&UserKey=#{self.api_key}"
5
+ JSON(response.body)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Similarweb
2
+ module Keywords
3
+ def keywords(domain)
4
+ response = self.http_client.get "#{domain}/v1/searchintelligence?Format=JSON&UserKey=#{self.api_key}"
5
+ JSON(response.body)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Similarweb
2
+ module Referrals
3
+ def referrals(domain)
4
+ response = self.http_client.get "#{domain}/v2/leadingreferringsites?Format=JSON&UserKey=#{self.api_key}"
5
+ JSON(response.body)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Similarweb
2
+ module SimilarSites
3
+ def similar_sites(domain)
4
+ response = self.http_client.get "#{domain}/v2/similarsites?Format=JSON&UserKey=#{self.api_key}"
5
+ JSON(response.body)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Similarweb
2
+ module SocialReferrals
3
+ def social_referrals(domain)
4
+ response = self.http_client.get "#{domain}/v1/socialreferringsites?Format=JSON&UserKey=#{self.api_key}"
5
+ JSON(response.body)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Similarweb
2
+ module Tags
3
+ def tags(domain)
4
+ response = self.http_client.get "#{domain}/v2/tags?Format=JSON&UserKey=#{self.api_key}"
5
+ JSON(response.body)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Similarweb
2
+ module Traffic
3
+ def traffic(domain)
4
+ response = self.http_client.get "#{domain}/v1/traffic?Format=JSON&UserKey=#{self.api_key}"
5
+ JSON(response.body)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Similarweb
2
+ VERSION = "0.0.1"
3
+ end
data/lib/similarweb.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ require 'similarweb/version'
5
+ require 'similarweb/also_visited'
6
+ require 'similarweb/category'
7
+ require 'similarweb/category_rank'
8
+ require 'similarweb/destinations'
9
+ require 'similarweb/engagement'
10
+ require 'similarweb/estimated_visits'
11
+ require 'similarweb/keywords'
12
+ require 'similarweb/referrals'
13
+ require 'similarweb/similar_sites'
14
+ require 'similarweb/social_referrals'
15
+ require 'similarweb/tags'
16
+ require 'similarweb/traffic'
17
+ require 'similarweb/client'
18
+
19
+
20
+ module Similarweb
21
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'similarweb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "similarweb"
8
+ spec.version = Similarweb::VERSION
9
+ spec.authors = ["John McLaughlin", "Steven Lai"]
10
+ spec.email = ["j@yar.com", "mailto:lai.steven@gmail.com"]
11
+ spec.summary = %q{Ruby wrapper for Similarweb API}
12
+ spec.description = %q{Ruby wrapper for Similarweb API}
13
+ spec.homepage = "http://github.com/johnmcl/similarweb"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "faraday"
26
+ spec.add_development_dependency "webmock"
27
+ end
@@ -0,0 +1,434 @@
1
+ require 'spec_helper'
2
+
3
+ describe Similarweb::Client do
4
+ before do
5
+ @client = Similarweb::Client.new(api_key: 'test-key')
6
+ end
7
+
8
+ describe '.api_key' do
9
+ it 'should return the api key' do
10
+ expect( @client.api_key ).to eq('test-key')
11
+ end
12
+ end
13
+
14
+ describe '.referrals' do
15
+ before(:each) do
16
+ body = <<-eos
17
+ {
18
+ "Sites": [
19
+ "bleacherreport.com",
20
+ "spox.com",
21
+ "sportal.com.au",
22
+ "espn.go.com",
23
+ "en.wikipedia.org",
24
+ "nba.co.jp",
25
+ "search.tb.ask.com",
26
+ "gazzetta.it",
27
+ "baloncesto.as.com",
28
+ "forums.realgm.com"
29
+ ],
30
+ "StartDate": "01/2014",
31
+ "EndDate": "03/2014"
32
+ }
33
+ eos
34
+
35
+ stub_request(:get, "http://api.similarweb.com/Site/example.com/v2/leadingreferringsites?Format=JSON&UserKey=test-key").
36
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.0'}).
37
+ to_return(:status => 200, :body => body, :headers => {})
38
+
39
+ @referrals = @client.referrals('example.com')
40
+ end
41
+
42
+ it 'should return a list of referral sites' do
43
+ expect( @referrals ).to have_key('Sites')
44
+ expect( @referrals['Sites']).to be_a(Array)
45
+ end
46
+ end
47
+
48
+ describe '.keywords' do
49
+ before(:each) do
50
+ body = <<-eos
51
+ {
52
+ "OrganicSearchShare": 0.9894885348395134,
53
+ "PaidSearchShare": 0.010511465160486622,
54
+ "TopOrganicTerms": [
55
+ "nba",
56
+ "nba.com",
57
+ "nba standings",
58
+ "nba league pass",
59
+ "miami heat",
60
+ "nba store",
61
+ "lakers",
62
+ "chicago bulls",
63
+ "knicks",
64
+ "houston rockets"
65
+ ],
66
+ "TopPaidTerms": [
67
+ "nba store",
68
+ "nba",
69
+ "nba league pass",
70
+ "nba shop",
71
+ "nba.com",
72
+ "orlando magic",
73
+ "portland trail blazers",
74
+ "miami heat",
75
+ "nba jerseys",
76
+ "celtics"
77
+ ],
78
+ "StartDate": "01/2014",
79
+ "EndDate": "03/2014"
80
+ }
81
+ eos
82
+
83
+ stub_request(:get, "http://api.similarweb.com/Site/example.com/v1/searchintelligence?Format=JSON&UserKey=test-key").
84
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.0'}).
85
+ to_return(:status => 200, :body => body, :headers => {})
86
+
87
+ @keywords = @client.keywords('example.com')
88
+ end
89
+
90
+ it 'should return a ratio of organic search share' do
91
+ expect( @keywords ).to have_key('OrganicSearchShare')
92
+ end
93
+
94
+ it 'should return a ratio of paid search share' do
95
+ expect( @keywords ).to have_key('PaidSearchShare')
96
+ end
97
+
98
+ it 'should return a list of top organic search terms' do
99
+ expect( @keywords ).to have_key('TopOrganicTerms')
100
+ expect( @keywords['TopOrganicTerms'] ).to be_a(Array)
101
+ end
102
+
103
+ it 'should return a list of top paid terms' do
104
+ expect( @keywords ).to have_key('TopPaidTerms')
105
+ expect( @keywords['TopPaidTerms'] ).to be_a(Array)
106
+ end
107
+ end
108
+
109
+ describe '.estimated_visits' do
110
+ before(:each) do
111
+ body = <<-eos
112
+ {
113
+ "EstimatedVisitors": 81178601
114
+ }
115
+ eos
116
+
117
+ stub_request(:get, "http://api.similarweb.com/Site/example.com/v1/EstimatedTraffic?Format=JSON&UserKey=test-key").
118
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.0'}).
119
+ to_return(:status => 200, :body => body, :headers => {})
120
+
121
+ @estimated_visitors = @client.estimated_visits('example.com')
122
+ end
123
+
124
+ it 'should have estimated visitors' do
125
+ expect( @estimated_visitors ).to have_key('EstimatedVisitors')
126
+ end
127
+ end
128
+
129
+ describe '.engagement' do
130
+ before(:each) do
131
+ body = <<-eos
132
+ {
133
+ "AveragePageViews": 4.230206634619614,
134
+ "AverageTimeOnSite": 368.58524742011434,
135
+ "BounceRate": 0.2642082587520108,
136
+ "Date": "03/2014"
137
+ }
138
+ eos
139
+
140
+ stub_request(:get, "http://api.similarweb.com/Site/example.com/v1/engagement?Format=JSON&UserKey=test-key").
141
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.0'}).
142
+ to_return(:status => 200, :body => body, :headers => {})
143
+
144
+ @engagement = @client.engagement('example.com')
145
+ end
146
+
147
+ it 'should have average page views' do
148
+ expect( @engagement ).to have_key('AveragePageViews')
149
+ end
150
+
151
+ it 'should have average time on site' do
152
+ expect( @engagement ).to have_key('AverageTimeOnSite')
153
+ end
154
+
155
+ it 'should have bounce rate' do
156
+ expect( @engagement ).to have_key('BounceRate')
157
+ end
158
+
159
+ it 'should have date' do
160
+ expect( @engagement ).to have_key('Date')
161
+ end
162
+ end
163
+
164
+ describe '.destinations' do
165
+ before(:each) do
166
+ body = <<-eos
167
+ {
168
+ "Sites": [
169
+ "test.com",
170
+ "faketest.com"
171
+ ],
172
+ "StartDate": "01/2014",
173
+ "EndDate": "03/2014"
174
+ }
175
+ eos
176
+
177
+ stub_request(:get, "http://api.similarweb.com/Site/example.com/v2/leadingdestinationsites?Format=JSON&UserKey=test-key").
178
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.0'}).
179
+ to_return(:status => 200, :body => body, :headers => {})
180
+
181
+ @destinations = @client.destinations('example.com')
182
+ end
183
+
184
+ it 'should return a list of sites' do
185
+ expect( @destinations["Sites"] ).to be_a(Array)
186
+ end
187
+ end
188
+
189
+ describe '.category' do
190
+ before(:each) do
191
+ body = <<-eos
192
+ {
193
+ "Category": "Sports/Basketball"
194
+ }
195
+ eos
196
+
197
+ stub_request(:get, "http://api.similarweb.com/Site/example.com/v2/category?Format=JSON&UserKey=test-key").
198
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.0'}).
199
+ to_return(:status => 200, :body => body, :headers => {})
200
+
201
+ @category = @client.category('example.com')
202
+ end
203
+
204
+ it 'should return a category' do
205
+ expect( @category ).to have_key('Category')
206
+ end
207
+ end
208
+
209
+ describe '.category_rank' do
210
+ before(:each) do
211
+ body = <<-eos
212
+ {
213
+ "Category": "Sports/Basketball",
214
+ "CategoryRank": 1
215
+ }
216
+ eos
217
+
218
+ stub_request(:get, "http://api.similarweb.com/Site/example.com/v2/CategoryRank?Format=JSON&UserKey=test-key").
219
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.0'}).
220
+ to_return(:status => 200, :body => body, :headers => {})
221
+
222
+ @category_rank = @client.category_rank('example.com')
223
+ end
224
+
225
+ it 'should return a category' do
226
+ expect( @category_rank ).to have_key('Category')
227
+ end
228
+
229
+ it 'should return a rank' do
230
+ expect( @category_rank ).to have_key('CategoryRank')
231
+ end
232
+ end
233
+
234
+ describe '.also_visited' do
235
+ before(:each) do
236
+ body = <<-eos
237
+ {
238
+ "AlsoVisited": [
239
+ {
240
+ "Url": "nfl.com",
241
+ "Score": 0.005021070143807851
242
+ }
243
+ ]
244
+ }
245
+ eos
246
+
247
+ stub_request(:get, "http://api.similarweb.com/Site/example.com/v2/alsovisited?Format=JSON&UserKey=test-key").
248
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.0'}).
249
+ to_return(:status => 200, :body => body, :headers => {})
250
+
251
+ @also_visited_metrics = @client.also_visited('example.com')
252
+ end
253
+
254
+ it 'should return a list of also visited sites' do
255
+ expect(@also_visited_metrics["AlsoVisited"]).to be_a(Array)
256
+ end
257
+
258
+ describe 'similar site' do
259
+ it 'should have a url' do
260
+ expect(@also_visited_metrics["AlsoVisited"].first).to have_key('Url')
261
+ end
262
+
263
+ it 'should have a score' do
264
+ expect(@also_visited_metrics["AlsoVisited"].first).to have_key('Score')
265
+ end
266
+ end
267
+ end
268
+
269
+ describe '.traffic' do
270
+ before(:each) do
271
+ body = <<-eos
272
+ {
273
+ "GlobalRank": 327,
274
+ "CountryCode": 840,
275
+ "CountryRank": 251,
276
+ "TopCountryShares": [
277
+ {
278
+ "CountryCode": 840,
279
+ "TrafficShare": 0.4274051669391115
280
+ }]
281
+ }
282
+ eos
283
+
284
+ stub_request(:get, "http://api.similarweb.com/Site/example.com/v1/traffic?Format=JSON&UserKey=test-key").
285
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.0'}).
286
+ to_return(:status => 200, :body => body, :headers => {})
287
+
288
+ @traffic_metrics = @client.traffic('example.com')
289
+ end
290
+
291
+ it 'should return the traffic metrics with global rank' do
292
+ expect( @traffic_metrics ).to have_key('GlobalRank')
293
+ end
294
+
295
+ it 'should return the traffic metrics with country code' do
296
+ expect( @traffic_metrics ).to have_key('CountryCode')
297
+ end
298
+
299
+ it 'should return the traffic metrics with country rank' do
300
+ expect( @traffic_metrics ).to have_key('CountryRank')
301
+ end
302
+
303
+ it 'should return the traffic metrics with top country shares' do
304
+ expect( @traffic_metrics ).to have_key('TopCountryShares')
305
+ end
306
+
307
+ it 'should return a list of countries and the traffic share' do
308
+ expect( @traffic_metrics['TopCountryShares'] ).to be_a(Array)
309
+ end
310
+ end
311
+
312
+ describe '.similar_sites' do
313
+ before(:each) do
314
+ body = <<-eos
315
+ {
316
+ "SimilarSites": [
317
+ {
318
+ "Url": "pbskids.org",
319
+ "Score": 0.9012942574949001
320
+ },
321
+ {
322
+ "Url": "nick.com",
323
+ "Score": 0.7312487797958783
324
+ },
325
+ {
326
+ "Url": "kids.yahoo.com",
327
+ "Score": 0.6653412685291096
328
+ }
329
+ ]
330
+ }
331
+ eos
332
+
333
+ stub_request(:get, "http://api.similarweb.com/Site/disney.com/v2/similarsites?Format=JSON&UserKey=test-key").
334
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.0'}).
335
+ to_return(:status => 200, :body => body, :headers => {})
336
+
337
+ @similar_sites = @client.similar_sites('disney.com')
338
+ end
339
+
340
+ it 'should return a list of similar sites' do
341
+ expect(@similar_sites["SimilarSites"]).to be_a(Array)
342
+ end
343
+
344
+ describe 'site tags' do
345
+ it 'should have a name' do
346
+ expect(@similar_sites["SimilarSites"].first).to have_key('Url')
347
+ end
348
+
349
+ it 'should have a score' do
350
+ expect(@similar_sites["SimilarSites"].first).to have_key('Score')
351
+ end
352
+ end
353
+ end
354
+
355
+
356
+ describe '.social_referrals' do
357
+ before(:each) do
358
+ body = <<-eos
359
+ {
360
+ "SocialSources": [
361
+ {
362
+ "Source": "Youtube",
363
+ "Value": 0.699753626365037
364
+ },
365
+ {
366
+ "Source": "Reddit",
367
+ "Value": 0.06447515408116457
368
+ }
369
+ ]
370
+ }
371
+ eos
372
+
373
+ stub_request(:get, "http://api.similarweb.com/Site/disney.com/v1/socialreferringsites?Format=JSON&UserKey=test-key").
374
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.0'}).
375
+ to_return(:status => 200, :body => body, :headers => {})
376
+
377
+ @social_referrals = @client.social_referrals('disney.com')
378
+ end
379
+
380
+ it 'should return a list of social referrals' do
381
+ expect(@social_referrals["SocialSources"]).to be_a(Array)
382
+ end
383
+
384
+ describe 'site tags' do
385
+ it 'should have a name' do
386
+ expect(@social_referrals["SocialSources"].first).to have_key('Source')
387
+ end
388
+
389
+ it 'should have a score' do
390
+ expect(@social_referrals["SocialSources"].first).to have_key('Value')
391
+ end
392
+ end
393
+ end
394
+
395
+ describe '.tags' do
396
+ before(:each) do
397
+ body = <<-eos
398
+ {
399
+ "Tags": [
400
+ {
401
+ "Name": "disney",
402
+ "Score": 0.4535382529673987
403
+ },
404
+ {
405
+ "Name": "kids",
406
+ "Score": 0.16695504510907133
407
+ }
408
+ ]
409
+ }
410
+ eos
411
+
412
+ stub_request(:get, "http://api.similarweb.com/Site/disney.com/v2/tags?Format=JSON&UserKey=test-key").
413
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.0'}).
414
+ to_return(:status => 200, :body => body, :headers => {})
415
+
416
+ @website_tags = @client.tags('disney.com')
417
+ end
418
+
419
+ it 'should return a list of tags' do
420
+ expect(@website_tags["Tags"]).to be_a(Array)
421
+ end
422
+
423
+ describe 'site tags' do
424
+ it 'should have a name' do
425
+ expect(@website_tags["Tags"].first).to have_key('Name')
426
+ end
427
+
428
+ it 'should have a score' do
429
+ expect(@website_tags["Tags"].first).to have_key('Score')
430
+ end
431
+ end
432
+ end
433
+
434
+ end
@@ -0,0 +1,25 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+
18
+ config.before(:each) do
19
+ end
20
+ end
21
+
22
+ require 'webmock/rspec'
23
+ require 'similarweb'
24
+
25
+ WebMock.disable_net_connect!(allow_localhost: true)
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: similarweb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John McLaughlin
9
+ - Steven Lai
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-04-10 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '1.5'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.5'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rake
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: pry
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: faraday
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: webmock
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Ruby wrapper for Similarweb API
112
+ email:
113
+ - j@yar.com
114
+ - mailto:lai.steven@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE.md
123
+ - README.md
124
+ - Rakefile
125
+ - lib/similarweb.rb
126
+ - lib/similarweb/also_visited.rb
127
+ - lib/similarweb/category.rb
128
+ - lib/similarweb/category_rank.rb
129
+ - lib/similarweb/client.rb
130
+ - lib/similarweb/destinations.rb
131
+ - lib/similarweb/engagement.rb
132
+ - lib/similarweb/estimated_visits.rb
133
+ - lib/similarweb/keywords.rb
134
+ - lib/similarweb/referrals.rb
135
+ - lib/similarweb/similar_sites.rb
136
+ - lib/similarweb/social_referrals.rb
137
+ - lib/similarweb/tags.rb
138
+ - lib/similarweb/traffic.rb
139
+ - lib/similarweb/version.rb
140
+ - similarweb.gemspec
141
+ - spec/similarweb/client_spec.rb
142
+ - spec/spec_helper.rb
143
+ homepage: http://github.com/johnmcl/similarweb
144
+ licenses:
145
+ - MIT
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 1.8.25
165
+ signing_key:
166
+ specification_version: 3
167
+ summary: Ruby wrapper for Similarweb API
168
+ test_files:
169
+ - spec/similarweb/client_spec.rb
170
+ - spec/spec_helper.rb
171
+ has_rdoc: