similarweb2.0 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7cb9e9749119e091c3f00cb85422f2f1eeb49be5
4
+ data.tar.gz: 174ee1dcb40bb0e27053726835f6cd7b6664f0b0
5
+ SHA512:
6
+ metadata.gz: 80742de448d4c151605aea8eb5e72e625745f13d66762021b77032cdec53afe4c0d2ad44b11b57115d81d519bc74bea221a3d599961c14425bbe27f800402aa0
7
+ data.tar.gz: 9a1c7c5a17d878f3c687332434fa042a134f4a9698b2f74e416db382ab057d191f77694f09b213d740f8661011b590792cdeeefa6767b116f7b4378c6d5ee9fc
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ /.bundle/
2
+ /Gemfile.lock
3
+ /spec/reports/
4
+ /tmp/
5
+ *.bundle
6
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in similarweb2.gemspec
4
+ gemspec
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,41 @@
1
+ # Similarweb2.0
2
+
3
+ Latest Ruby client for [SimilarWeb API](https://developer.similarweb.com/)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'similarweb2.0'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install similarweb2.0
18
+
19
+ ## Usage
20
+
21
+ ``` ruby
22
+ client = Similarweb::Client.new(api_key: key)
23
+ visit = client.desktop_visit('google.com', '2017-03', '2017-04', 'daily')
24
+ ```
25
+
26
+ ## Author
27
+ [Harsh Vardhan Sharma](mailto:bonnyharsh1993@gmail.com)
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( http://github.com/harshvardhansharma/similarweb2.0/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
36
+
37
+ ## Copyright
38
+ Copyright (c) 2014 [Harsh Vardhan Sharma](mailto:bonnyharsh1993@gmail.com).
39
+ See [LICENSE][license] for details.
40
+
41
+ [license]: LICENSE.md
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
data/circle.yml ADDED
@@ -0,0 +1,3 @@
1
+ test:
2
+ override:
3
+ - RAILS_ENV=test bundle exec rspec
@@ -0,0 +1,31 @@
1
+ module Similarweb
2
+ class Client
3
+ include DesktopTraffic::Sources
4
+ include DesktopTraffic::SearchKeyword
5
+ include Traffic::BounceRate
6
+ include Traffic::PageView
7
+ include Traffic::Visit
8
+ include Traffic::VisitDuration
9
+ include Traffic::TotalEngagement
10
+
11
+ attr_accessor :api_key, :http_client
12
+
13
+ def initialize(args = {})
14
+ args.each do |key, value|
15
+ send(:"#{key}=", value)
16
+ end
17
+ make_http_client!
18
+ end
19
+
20
+ private
21
+
22
+ def make_http_client!
23
+ base_url = "http://api.similarweb.com/"
24
+ self.http_client = Faraday.new(:url => base_url) do |builder|
25
+ builder.request :url_encoded
26
+ builder.response :follow_redirects, limit: 3
27
+ builder.adapter Faraday.default_adapter
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ module Similarweb
2
+ module DesktopTraffic
3
+ module SearchKeyword
4
+
5
+ # NOTE: start_date, end_date format: YYYY-MM
6
+
7
+ def organic_search_keyword(domain, start_date, end_date, limit = nil)
8
+ response = self.http_client.get "v1/website/#{domain}/traffic-sources/organic-search?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&limit=#{limit}"
9
+ JSON.parse(response.body)
10
+ end
11
+
12
+ def paid_search_keyword(domain, start_date, end_date, limit = nil)
13
+ response = self.http_client.get "v1/website/#{domain}/traffic-sources/paid-search?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&limit=#{limit}"
14
+ JSON.parse(response.body)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Similarweb
2
+ module DesktopTraffic
3
+ module Sources
4
+
5
+ # NOTE: start_date, end_date format: YYYY-MM
6
+
7
+ def overview_share(domain, start_date, end_date)
8
+ response = self.http_client.get "v1/website/#{domain}/traffic-sources/overview-share?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&main_domain_only=false"
9
+ JSON.parse(response.body)
10
+ end
11
+
12
+ def overview(domain, start_date, end_date)
13
+ response = self.http_client.get "v1/website/#{domain}/traffic-sources/overview?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&main_domain_only=false"
14
+ JSON.parse(response.body)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Similarweb
2
+ module Traffic
3
+ module BounceRate
4
+
5
+ # NOTE: start_date, end_date format: YYYY-MM
6
+
7
+ def desktop_bounce_rate(domain, start_date, end_date, granularity = 'daily')
8
+ response = self.http_client.get "v1/website/#{domain}/traffic-and-engagement/bounce-rate?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&main_domain_only=false&granularity=#{granularity}"
9
+ JSON.parse(response.body)
10
+ end
11
+
12
+ def mobile_bounce_rate(domain, start_date, end_date, granularity = 'daily')
13
+ response = self.http_client.get "v2/website/#{domain}/mobile-web/bounce-rate?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&granularity=#{frequency}"
14
+ JSON.parse(response.body)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Similarweb
2
+ module Traffic
3
+ module PageView
4
+
5
+ # NOTE: start_date, end_date format: YYYY-MM
6
+
7
+ def desktop_page_view(domain, start_date, end_date, granularity = 'daily')
8
+ response = self.http_client.get "v1/website/#{domain}/traffic-and-engagement/pages-per-visit?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&main_domain_only=false&granularity=#{granularity}"
9
+ JSON.parse(response.body)
10
+ end
11
+
12
+ def mobile_page_view(domain, start_date, end_date, granularity = 'daily')
13
+ response = self.http_client.get "v2/website/#{domain}/mobile-web/pages-per-visit?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&granularity=#{frequency}"
14
+ JSON.parse(response.body)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ module Similarweb
2
+ module Traffic
3
+ module TotalEngagement
4
+
5
+ # NOTE: start_date, end_date format: YYYY-MM
6
+
7
+ def visit(domain, start_date, end_date, granularity = 'daily')
8
+ response = self.http_client.get "v1/website/#{domain}/total-traffic-and-engagement/visits?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&main_domain_only=false&granularity=#{granularity}"
9
+ JSON.parse(response.body)
10
+ end
11
+
12
+ def pages_per_visit(domain, start_date, end_date, granularity = 'daily')
13
+ response = self.http_client.get "v1/website/#{domain}/total-traffic-and-engagement/pages-per-visit?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&main_domain_only=false&granularity=#{granularity}"
14
+ JSON.parse(response.body)
15
+ end
16
+
17
+ def average_visit_duration(domain, start_date, end_date, granularity = 'daily')
18
+ response = self.http_client.get "v1/website/#{domain}/total-traffic-and-engagement/average-visit-duration?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&main_domain_only=false&granularity=#{granularity}"
19
+ JSON.parse(response.body)
20
+ end
21
+
22
+ def bounce_rate(domain, start_date, end_date, granularity = 'daily')
23
+ response = self.http_client.get "v1/website/#{domain}/total-traffic-and-engagement/bounce-rate?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&main_domain_only=false&granularity=#{granularity}"
24
+ JSON.parse(response.body)
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ module Similarweb
2
+ module Traffic
3
+ module Visit
4
+
5
+ # NOTE: start_date, end_date format: YYYY-MM
6
+
7
+ def desktop_visit(domain, start_date, end_date, granularity = 'daily')
8
+ response = self.http_client.get "v1/website/#{domain}/traffic-and-engagement/visits?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&main_domain_only=false&granularity=#{granularity}"
9
+ JSON.parse(response.body)
10
+ end
11
+
12
+ def mobile_visit(domain, start_date, end_date, granularity = 'daily')
13
+ response = self.http_client.get "v2/website/#{domain}/mobile-web/visits?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&granularity=#{granularity}"
14
+ JSON.parse(response.body)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Similarweb
2
+ module Traffic
3
+ module VisitDuration
4
+
5
+ # NOTE: start_date, end_date format: YYYY-MM
6
+
7
+ def desktop_visit_duration(domain, start_date, end_date, granularity = 'daily')
8
+ response = self.http_client.get "v1/website/#{domain}/traffic-and-engagement/average-visit-duration?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&main_domain_only=false&granularity=#{granularity}"
9
+ JSON.parse(response.body)
10
+ end
11
+
12
+ def mobile_visit_duration(domain, start_date, end_date, granularity = 'daily')
13
+ response = self.http_client.get "v2/website/#{domain}/mobile-web/average-visit-duration?api_key=#{self.api_key}&start_date=#{start_date}&end_date=#{end_date}&granularity=#{frequency}"
14
+ JSON.parse(response.body)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Similarweb
2
+ VERSION = '0.0.1'
3
+ end
data/lib/similarweb.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'json'
4
+
5
+ require 'similarweb/version'
6
+ require 'similarweb/desktop_traffic/search_keyword'
7
+ require 'similarweb/desktop_traffic/sources'
8
+ require 'similarweb/traffic/bounce_rate'
9
+ require 'similarweb/traffic/page_view'
10
+ require 'similarweb/traffic/total_engagement'
11
+ require 'similarweb/traffic/visit'
12
+ require 'similarweb/traffic/visit_duration'
13
+ require 'similarweb/client'
14
+
15
+ module Similarweb
16
+ end
@@ -0,0 +1,28 @@
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 = 'similarweb2.0'
8
+ spec.version = Similarweb::VERSION
9
+ spec.authors = ['Harsh Vardhan Sharma']
10
+ spec.email = ['bonnyharsh1993@gmail.com']
11
+ spec.summary = %q{Ruby wrapper for Similarweb API}
12
+ spec.description = %q{Ruby wrapper for Similarweb API}
13
+ spec.homepage = 'https://github.com/harshvardhansharma/similarweb2.0'
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 'webmock'
25
+
26
+ spec.add_runtime_dependency 'faraday', '~>0.12.1'
27
+ spec.add_runtime_dependency 'faraday_middleware', '~>0.11'
28
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe Similarweb::Client do
4
+
5
+ let(:api_key) { 'abcde-12345' }
6
+
7
+ before do
8
+ @client = Similarweb::Client.new(api_key: api_key)
9
+ end
10
+
11
+ describe '.api_key' do
12
+ it 'should return the api key' do
13
+ expect( @client.api_key ).to eq(api_key)
14
+ end
15
+ end
16
+
17
+ describe '.desktop_visit' do
18
+ before(:each) do
19
+ body = <<-eos
20
+ {
21
+ "meta": {
22
+ "request": {
23
+ "granularity": "Daily",
24
+ "main_domain_only": false,
25
+ "domain": "example.com",
26
+ "country": "world"
27
+ },
28
+ "status": "Success",
29
+ "last_updated": "2017-01-17"
30
+ },
31
+ "visits": [
32
+ {
33
+ "date": "2017-01-16",
34
+ "visits": 1328398.73631
35
+ },
36
+ {
37
+ "date": "2017-01-17",
38
+ "visits": 1547400.88473
39
+ }
40
+ ]
41
+ }
42
+ eos
43
+
44
+ start_date = '2017-02'
45
+ end_date = '2017-03'
46
+
47
+ stub_request(:get, "http://api.similarweb.com/v1/website/example.com/traffic-and-engagement/visits?api_key=#{api_key}&end_date=#{end_date}&granularity=daily&main_domain_only=false&start_date=#{start_date}").
48
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.12.1'}).
49
+ to_return(:status => 200, :body => body, :headers => {})
50
+ @desktop_visit = @client.desktop_visit('example.com', start_date, end_date)
51
+ end
52
+
53
+ it 'should return a list of desktop_visit' do
54
+ expect( @desktop_visit ).to have_key('visits')
55
+ expect( @desktop_visit['visits']).to be_a(Array)
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,18 @@
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
+ # Run specs in random order to surface order dependencies. If you find an
9
+ # order dependency and want to debug it, you can fix the order by providing
10
+ # the seed, which is printed after each run.
11
+ # --seed 1234
12
+ config.order = 'random'
13
+ end
14
+
15
+ require 'webmock/rspec'
16
+ require 'similarweb'
17
+
18
+ WebMock.disable_net_connect!(allow_localhost: true)
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: similarweb2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Harsh Vardhan Sharma
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.12.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.12.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday_middleware
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.11'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.11'
97
+ description: Ruby wrapper for Similarweb API
98
+ email:
99
+ - bonnyharsh1993@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.md
107
+ - README.md
108
+ - Rakefile
109
+ - circle.yml
110
+ - lib/similarweb.rb
111
+ - lib/similarweb/client.rb
112
+ - lib/similarweb/desktop_traffic/search_keyword.rb
113
+ - lib/similarweb/desktop_traffic/sources.rb
114
+ - lib/similarweb/traffic/bounce_rate.rb
115
+ - lib/similarweb/traffic/page_view.rb
116
+ - lib/similarweb/traffic/total_engagement.rb
117
+ - lib/similarweb/traffic/visit.rb
118
+ - lib/similarweb/traffic/visit_duration.rb
119
+ - lib/similarweb/version.rb
120
+ - similarweb2.gemspec
121
+ - spec/similarweb/client_spec.rb
122
+ - spec/spec_helper.rb
123
+ homepage: https://github.com/harshvardhansharma/similarweb2.0
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.4.8
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Ruby wrapper for Similarweb API
147
+ test_files:
148
+ - spec/similarweb/client_spec.rb
149
+ - spec/spec_helper.rb