spyfu 0.0.4 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d165dba4f35f660a02dba1a7a79ce992915e26c
4
- data.tar.gz: e91bcfc5217810c0a97eb4c5d80a1b3bcead2002
3
+ metadata.gz: 5f5468bed9e0b0f35e1fbc09f2da59ee9d5d4baf
4
+ data.tar.gz: 8a457d1cea2074b0e6513405cb6a18f9bcf709fb
5
5
  SHA512:
6
- metadata.gz: 69b427836a276edac24c8ea9b0851ded4737e77b8807ada04c76a9ed63df3ddac5989c3d304d82f0bd13d87cbd12b3cb6774a0a2b9638cae145ffe4ca0ef2c18
7
- data.tar.gz: 3c432be117e0ca70f6fc38dcab68640641d30ef131769cd653ec2647093c512e1dbb3b0951477db182ad4c51136db5a461149b11e8b8a957e13c4a2441d62e8e
6
+ metadata.gz: e1d7c2ffc1d8f2fca570f5a0c66afbd06ae9ac154539f2f255c9e05f8ec73f823be91011f4745b1a8c4a7721c1c8338a987403b95db6ad80c15b818fe891186d
7
+ data.tar.gz: e33c415760ccacdde1dbcde97c38f097d50b105f904b0b42a3d204fa7040a9700f178d62071edc5de807dd0e1877292c6600d90f9d9a02f23b0e4a8d04fa0e93
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Robert Graff
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,109 @@
1
+ # spyfu-rb
2
+
3
+ An unofficial gem to access the [SpyFu API](https://www.spyfu.com/api). It requires [a SpyFu account](https://www.spyfu.com/api/get-started).
4
+
5
+ # Making a request
6
+
7
+ Here is a simple example on how to make a request to the API. A full listing of available params on available on [official site](https://www.spyfu.com/api).
8
+
9
+ ```ruby
10
+ spyfu = SpyFu.client('1234-12345-12345-1234', 'YOURSECRETKEY')
11
+ result = spyfu.kss_api.get_term_page_keywords(:q => 'spyfu api', :r => 100)
12
+ result.body # API returns a JSON object with results
13
+ ```
14
+
15
+ # Getting Started
16
+
17
+ Get started by `gem install spyfu` or in your Gemfile:
18
+
19
+ ```ruby
20
+ gem 'spyfu'
21
+ ```
22
+
23
+ # API
24
+
25
+ ## Ad History API
26
+
27
+ You can access the [Core API](https://www.spyfu.com/api/docs/core).
28
+
29
+ ```ruby
30
+ spyfu.ad_history_api.domain_ad_history(...)
31
+ spyfu.ad_history_api.domain_ad_history_with_metrics(...)
32
+ spyfu.ad_history_api.term_ad_history(...)
33
+ ```
34
+
35
+ ## Core API
36
+
37
+ You can access the [Core API](https://www.spyfu.com/api/docs/core).
38
+
39
+ ```ruby
40
+ spyfu.core_api.get_domain_metrics_us(...)
41
+ spyfu.core_api.get_domain_metrics_uk(...)
42
+ spyfu.core_api.get_domain_budget_history_us(...)
43
+ spyfu.core_api.get_domain_budget_history_uk(...)
44
+ spyfu.core_api.get_domain_competitors_us(...)
45
+ spyfu.core_api.get_domain_competitors_uk(...)
46
+ ```
47
+
48
+ ## KSS API
49
+
50
+ You can access the [Keyword SmartSearch API](https://www.spyfu.com/api/docs/related-keywords).
51
+
52
+ ```ruby
53
+ spyfu.kss_api.related_keywords(:q => 'spyfu api', :r => 100)
54
+ spyfu.kss_api.domain_related_keywords(:q => 'spyfu api', :r => 100)
55
+ ```
56
+
57
+ ## Leads API
58
+
59
+ You can access the [Leads API](https://www.spyfu.com/api/docs/leads).
60
+
61
+ ```ruby
62
+ spyfu.leads_api.get_contact_card(...)
63
+ spyfu.leads_api.get_grid(...)
64
+ spyfu.leads_api.get_top_list(...)
65
+ ```
66
+
67
+ ## URL API
68
+
69
+ You can access the [URL API](https://www.spyfu.com/api/docs/url).
70
+
71
+ ```ruby
72
+ spyfu.url_api.organic_kws(:q => "http://resources.spyfu.com/blog/", :r => 100)
73
+ spyfu.url_api.paid_kws(:q => "http://resources.spyfu.com/blog/", :r => 100)
74
+ spyfu.url_api.paid_estimates(...)
75
+ spyfu.url_api.organic_estimates(...)
76
+ ```
77
+
78
+ ## Weekly Tracking API
79
+
80
+ You can access the [Weekly Tracking API](https://www.spyfu.com/api/docs/weekly-tracking).
81
+
82
+ ```ruby
83
+ spyfu.weekly_tracking_api.add_terms(...)
84
+ spyfu.weekly_tracking_api.get_groups(...)
85
+ spyfu.weekly_tracking_api.get_terms(...)
86
+ spyfu.weekly_tracking_api.get_term_data(...)
87
+ spyfu.weekly_tracking_api.delete_terms(...)
88
+ ```
89
+
90
+ # Known Issues
91
+
92
+ * Parameter values are not properly encoded. Doing so break the request signature.
93
+ * Multiple parameters with the same name and different values are not handled. I don't see where this is used but comments in SpyFu's sample code mentions it.
94
+ * Allow paramers to be more ruby like (:maxRows becomes :max_rows)
95
+
96
+
97
+ # Contributing to spyfu-rb
98
+
99
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
100
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
101
+ * Fork the project.
102
+ * Start a feature/bugfix branch.
103
+ * Commit and push until you are happy with your contribution.
104
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
105
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
106
+
107
+ # Copyright
108
+
109
+ Copyright (c) 2014 Robert Graff. See LICENSE.txt for further details.
@@ -0,0 +1,24 @@
1
+ module SpyFu
2
+ module Api
3
+ class AdHistory < Base
4
+ # More information: https://www.spyfu.com/apis/ad_history_api/domain_ad_history
5
+ BASE_ENDPOINT = 'ad_history_api'
6
+
7
+ # Get ad history by domain
8
+ def domain_ad_history(params)
9
+ send_get "domain_ad_history", params
10
+ end
11
+
12
+ # Get ad history by domain with metrics
13
+ def domain_ad_history_with_metrics(params)
14
+ send_get "domain_ad_history_with_metrics", params
15
+ end
16
+
17
+ # Get ad history by domain by Term
18
+ def term_ad_history(params)
19
+ send_get "term_ad_history", params
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module SpyFu
2
+ module Api
3
+ class Base
4
+ attr :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def send_get path, params
11
+ SpyFu::Request.new('GET', "#{self.class::BASE_ENDPOINT}/#{path}", params, nil, client.app_id, client.secret_key).request
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,39 @@
1
+ module SpyFu
2
+ module Api
3
+ class Core < Base
4
+ # More information: https://www.spyfu.com/api/docs/core
5
+ BASE_ENDPOINT = 'core_api'
6
+
7
+ # Get US metrics from domain
8
+ def get_domain_metrics_us(params)
9
+ send_get "get_domain_metrics_us", params
10
+ end
11
+
12
+ # Get UK metrics from domain
13
+ def get_domain_metrics_uk(params)
14
+ send_get "get_domain_metrics_uk", params
15
+ end
16
+
17
+ # Get history of US domain's budget
18
+ def get_domain_budget_history_us(params)
19
+ send_get "get_domain_budget_history_us", params
20
+ end
21
+
22
+ # Get history of UK domain's budget
23
+ def get_domain_budget_history_uk(params)
24
+ send_get "get_domain_budget_history_uk", params
25
+ end
26
+
27
+ # Get US competitors from domain
28
+ def get_domain_competitors_us(params)
29
+ send_get "get_domain_competitors_us", params
30
+ end
31
+
32
+ # Get UK competitors from domain
33
+ def get_domain_competitors_uk(params)
34
+ send_get "get_domain_competitors_uk", params
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,29 @@
1
+ module SpyFu
2
+ module Api
3
+ class Kss < Base
4
+ # More information: https://www.spyfu.com/apis/ad_history_api/domain_ad_history
5
+ BASE_ENDPOINT = 'kss_api'
6
+
7
+ # Get list of related keywords
8
+ def related_keywords(params)
9
+ send_get "kss_kws", params
10
+ end
11
+
12
+ # Get list of domains related to keyword
13
+ def domain_related_keywords(params)
14
+ send_get "kss_domains", params
15
+ end
16
+
17
+ # Backward compatibility
18
+ def get_term_page_keywords(params)
19
+ params[:q] = params[:keyword]
20
+ if !params[:maxRows].nil?
21
+ params[:r] = params[:maxRows]
22
+ params.delete(:maxRows)
23
+ end
24
+ related_keywords(params)
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ module SpyFu
2
+ module Api
3
+ class Leads < Base
4
+ # More information: https://www.spyfu.com/api/docs/leads
5
+ BASE_ENDPOINT = 'leads_api'
6
+
7
+ # Get list of contacts for a domain
8
+ def get_contact_card(params)
9
+ send_get "get_contact_card", params
10
+ end
11
+
12
+ # Get list of contact leads
13
+ def get_grid(params)
14
+ send_get "get_grid", params
15
+ end
16
+
17
+ # Get list of contacts for a domain
18
+ def get_top_list(params)
19
+ send_get "get_top_list", params
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,51 @@
1
+ module SpyFu
2
+ module Api
3
+ class Url < Base
4
+ # More information: https://www.spyfu.com/api/docs/url
5
+ BASE_ENDPOINT = 'url_api'
6
+
7
+ # Get paid data from url
8
+ def paid_kws(params)
9
+ # Adjust params for backward compatibility
10
+ if !params[:bgdsv].nil?
11
+ params[:egdsv] = params[:bgdsv]
12
+ params.delete(:bgdsv)
13
+ end
14
+
15
+ if !params[:bldsv].nil?
16
+ params[:eldsv] = params[:bldsv]
17
+ params.delete(:bldsv)
18
+ end
19
+
20
+ send_get "paid_kws", params
21
+ end
22
+
23
+ # Get organic data from url
24
+ def organic_kws(params)
25
+ # Adjust params for backward compatibility
26
+ if !params[:blmsv].nil?
27
+ params[:elmsv] = params[:blmsv]
28
+ params.delete(:blmsv)
29
+ end
30
+
31
+ if !params[:bgmsv].nil?
32
+ params[:egmsv] = params[:bgmsv]
33
+ params.delete(:bgmsv)
34
+ end
35
+
36
+ send_get "organic_kws", params
37
+ end
38
+
39
+ # Get paid estimates from url
40
+ def paid_estimates(params)
41
+ send_get "paid_estimates", params
42
+ end
43
+
44
+ # Get organic estimates from url
45
+ def organic_estimates(params)
46
+ send_get "organic_estimates", params
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,49 @@
1
+ module SpyFu
2
+ module Api
3
+ class WeeklyTracking < Base
4
+ # More information: https://www.spyfu.com/apis/WeeklyTracking_Api/get_groups
5
+ BASE_ENDPOINT = 'weeklytracking_api'
6
+
7
+ # Add terms to group
8
+ def add_terms(params)
9
+ send_get "add_terms", params
10
+ end
11
+
12
+ # Get list of groups by name
13
+ def get_groups(params)
14
+ send_get "get_groups", params
15
+ end
16
+
17
+ # Get list of groups by domain
18
+ def get_groups_by_domain(params)
19
+ send_get "get_groups_by_domain", params
20
+ end
21
+
22
+ # Get list of terms by list ID
23
+ def get_terms(params)
24
+ send_get "get_terms", params
25
+ end
26
+
27
+ # Get term metrics
28
+ def get_term_data(params)
29
+ send_get "get_term_data", params
30
+ end
31
+
32
+ # Delete term from group
33
+ def delete_term(params)
34
+ send_get "delete_term", params
35
+ end
36
+
37
+ # Delete group list
38
+ def delete_group(params)
39
+ send_get "delete_group", params
40
+ end
41
+
42
+ # Backward compatibility
43
+ def delete_terms(params)
44
+ delete_term(params)
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,34 @@
1
+ module SpyFu
2
+ class Client
3
+ attr :app_id, :secret_key
4
+
5
+ def initialize(app_id, secret_key)
6
+ @app_id = app_id
7
+ @secret_key = secret_key
8
+ end
9
+
10
+ def ad_history_api
11
+ SpyFu::Api::AdHistory.new(self)
12
+ end
13
+
14
+ def core_api
15
+ SpyFu::Api::Core.new(self)
16
+ end
17
+
18
+ def kss_api
19
+ SpyFu::Api::Kss.new(self)
20
+ end
21
+
22
+ def leads_api
23
+ SpyFu::Api::Leads.new(self)
24
+ end
25
+
26
+ def url_api
27
+ SpyFu::Api::Url.new(self)
28
+ end
29
+
30
+ def weekly_tracking_api
31
+ SpyFu::Api::WeeklyTracking.new(self)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,73 @@
1
+ require 'openssl'
2
+ require 'base64'
3
+ require 'net/http'
4
+ require 'time'
5
+
6
+ module SpyFu
7
+ class Request
8
+ attr :http_method, :params, :post_data, :app_id, :secret_key, :url
9
+
10
+ HTTP_HEADER_AUTHENTICATION = "Authentication"
11
+ HTTP_HEADER_TIMESTAMP = "Timestamp"
12
+ URL_API_BASE = "https://www.spyfu.com/apis/"
13
+
14
+ def initialize(http_method, endpoint, params, post_data, app_id, secret_key)
15
+ @http_method = http_method
16
+ @url = URL_API_BASE+endpoint
17
+ @params = params
18
+ @post_data = post_data
19
+ @app_id = app_id
20
+ @secret_key = secret_key
21
+ end
22
+
23
+ def request
24
+ req = Net::HTTP::Get.new(uri.request_uri)
25
+
26
+ # add authentiation goodness to request object
27
+ req[HTTP_HEADER_TIMESTAMP] = timestamp
28
+ req[HTTP_HEADER_AUTHENTICATION] = app_id + ":" + signature
29
+
30
+ request = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
31
+ http.request(req)
32
+ }
33
+ return request
34
+ end
35
+
36
+ def uri
37
+ @uri ||= URI(url+query_string)
38
+ end
39
+
40
+ def query_string
41
+ return '' if params.empty?
42
+ return '?'+params.map { |x| "#{x[0]}=#{x[1]}" }.join("&")
43
+ end
44
+
45
+ def timestamp
46
+ @timestamp ||= Time.now.getutc.strftime "%A, %B %d, %Y %I:%M:%S %p"
47
+ end
48
+
49
+ def message
50
+ @message ||= [http_method, timestamp, uri.path, parameter_message].join("\n")
51
+ end
52
+
53
+ def signature
54
+ digest = OpenSSL::Digest.new('sha256')
55
+ hmac_digest = OpenSSL::HMAC.digest(digest, secret_key, message)
56
+ Base64.encode64(hmac_digest).strip()
57
+ end
58
+
59
+ def parameter_message
60
+ return '' if parameter_collection.empty?
61
+ parameter_collection.map { |x| "#{x[0]}=#{x[1]}" }.join("&")
62
+ end
63
+
64
+ def parameter_collection
65
+ @parameter_collection ||= begin
66
+ collection = params.to_a + post_data.to_a
67
+ collection.sort
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spyfu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Graff
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-09-24 00:00:00.000000000 Z
12
+ date: 2017-09-28 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: The unofficial ruby gem for Spyfu.com
15
15
  email: workman@internetfaction.com
@@ -17,7 +17,18 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - LICENSE.txt
21
+ - README.md
20
22
  - lib/spyfu.rb
23
+ - lib/spyfu/api/ad_history.rb
24
+ - lib/spyfu/api/base.rb
25
+ - lib/spyfu/api/core.rb
26
+ - lib/spyfu/api/kss.rb
27
+ - lib/spyfu/api/leads.rb
28
+ - lib/spyfu/api/url.rb
29
+ - lib/spyfu/api/weekly_tracking.rb
30
+ - lib/spyfu/client.rb
31
+ - lib/spyfu/request.rb
21
32
  homepage: https://github.com/Workman/spyfu-rb
22
33
  licenses:
23
34
  - MIT
@@ -41,5 +52,5 @@ rubyforge_project:
41
52
  rubygems_version: 2.5.1
42
53
  signing_key:
43
54
  specification_version: 4
44
- summary: A simple API wrapper for Spyfu.com
55
+ summary: SpyFu API
45
56
  test_files: []