rb_raven_api 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.
data/README.md ADDED
@@ -0,0 +1,138 @@
1
+ Raven Tools API Gem [![Build Status](https://secure.travis-ci.org/mtchavez/rb-raven-api.png)](http://travis-ci.org/mtchavez/rb-raven-api?branch=master)
2
+ =============================
3
+
4
+ A wrapper around the RavenTools API calls.
5
+
6
+ * Github: http://github.com/mtchavez/rb-raven-api
7
+ * [![endorse](http://api.coderwall.com/mtchavez/endorsecount.png)](http://coderwall.com/mtchavez)
8
+
9
+ ## Install
10
+
11
+ gem install 'rb_raven_api'
12
+
13
+ ## Configuration
14
+
15
+ Set configuration options to be used on requests:
16
+
17
+ require 'rb_raven_api'
18
+
19
+ Raven.configure do |config|
20
+ config.api_key = 'my-key'
21
+ end
22
+
23
+ Or set your key without a block before making some requests:
24
+
25
+ require 'rb_raven_api'
26
+
27
+ Raven.configure 'my-key'
28
+
29
+ ## Profile
30
+
31
+ Get info pertaining to your RavenTools profile.
32
+
33
+ ### Info
34
+
35
+ This request will return the name and billable keyword usage for the current profile.
36
+
37
+ Raven::Profile.info
38
+
39
+ Example response in JSON
40
+
41
+ {
42
+ "name":"Tweetstalk",
43
+ "keyword_usage":"33"
44
+ }
45
+
46
+ ##Domains
47
+
48
+ API specific calls for domains.
49
+
50
+ ### All
51
+
52
+ This request will return the available domains for the profile associated with your API key.
53
+
54
+ Raven::Domain.all
55
+ # => ["example.com","tweetstalk.com"]
56
+
57
+ ### Add
58
+
59
+ The domain name you want to add. "www." prefixes are ignored for purposes of matching ranks, but will be stored as part of the domain name for future requests.
60
+
61
+ Raven::Domain.add 'poop-chute.com', '1,2,3'
62
+
63
+ Example response in JSON
64
+
65
+ {
66
+ "response":"success"
67
+ }
68
+
69
+ ### Keywords
70
+
71
+ This request will return the available keywords for the domain provided.
72
+
73
+ Raven::Domain.keywords 'poop-chute.com'
74
+
75
+ Example response in JSON
76
+
77
+ [
78
+ "toilets",
79
+ "plunger",
80
+ "toilet paper"
81
+ ]
82
+
83
+ ### Keywords with Tags
84
+
85
+ This request will return the available keywords for the domain provided.
86
+
87
+ Raven::Domain.keywords_with_tags 'poop-chute.com'
88
+
89
+ Example response in JSON
90
+
91
+ [
92
+ {
93
+ "keyword":"toilets",
94
+ "tags":null
95
+ },
96
+ {
97
+ "keyword":"plunger",
98
+ "tags":["one", "two"]
99
+ },
100
+ {
101
+ "keyword":"toilet paper",
102
+ "tags":["three"]
103
+ }
104
+ ]
105
+
106
+ ## Keywords
107
+
108
+ Keywords endpoint allows you to create and add keywords to a domain.
109
+
110
+ ### Add
111
+
112
+ This request will add keyword to the domain provided.
113
+
114
+ Raven::Keyword.add 'twitter.com', 'microblog'
115
+
116
+ Example response in JSON
117
+
118
+ {
119
+ "response":"success"
120
+ }
121
+
122
+ ### Remove
123
+
124
+ This request will remove a keyword from the domain provided.
125
+
126
+ Raven::Keyword.remove 'twitter.com', 'microblog'
127
+
128
+ Example response in JSON
129
+
130
+ {
131
+ "response":"success"
132
+ }
133
+
134
+ ## License
135
+
136
+ Written by Chavez
137
+
138
+ Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
data/lib/raven.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+ require 'net/http'
4
+ require 'hashie'
5
+
6
+ require File.dirname(__FILE__) + '/rb_raven_api/config'
7
+ require File.dirname(__FILE__) + '/rb_raven_api/domain'
8
+ require File.dirname(__FILE__) + '/rb_raven_api/engines'
9
+ require File.dirname(__FILE__) + '/rb_raven_api/http'
10
+ require File.dirname(__FILE__) + '/rb_raven_api/keyword'
11
+ require File.dirname(__FILE__) + '/rb_raven_api/profile'
12
+ require File.dirname(__FILE__) + '/rb_raven_api/request_error'
13
+ require File.dirname(__FILE__) + '/rb_raven_api/response'
14
+
15
+ module Raven
16
+
17
+ extend self
18
+
19
+ ##
20
+ # @example Configure takes block to set API key to be used in API calls.
21
+ # Raven.configure do |config|
22
+ # config.api_key = 'my-key'
23
+ # end
24
+ # @example Configure can also just take an api_key
25
+ # Raven.configure 'my-key'
26
+ #
27
+
28
+ def configure api_key = nil
29
+ if block_given?
30
+ yield config
31
+ else
32
+ config.api_key = api_key
33
+ end
34
+ end
35
+
36
+ #
37
+ # @return [Raven::Config]
38
+
39
+ def config
40
+ @config ||= Config.new
41
+ end
42
+
43
+ def http # @private
44
+ Http.new(config)
45
+ end
46
+
47
+ end
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/raven'
@@ -0,0 +1,27 @@
1
+ module Raven
2
+
3
+ ##
4
+ #
5
+ # Config class used internally.
6
+ # Configure API calls using Raven.configure
7
+
8
+ class Config
9
+
10
+ DEFAULT_HOST = 'https://api.raventools.com/api'
11
+ DEFAULT_PORT = 80 # @private
12
+
13
+ attr_accessor :api_key
14
+ attr_reader :host, :port # @private
15
+
16
+ ##
17
+ #
18
+ # @private
19
+
20
+ def initialize
21
+ @host = DEFAULT_HOST
22
+ @port = DEFAULT_PORT
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,48 @@
1
+ module Raven
2
+
3
+ class Domain
4
+
5
+ ##
6
+ # Your account domains.
7
+ #
8
+ # @return [Array] Domains.
9
+ #
10
+
11
+ def self.all
12
+ Raven.http.get '', { method: 'domains' }
13
+ end
14
+
15
+ ##
16
+ # This request will add the domain provided.
17
+ #
18
+ # @param domain [String] *Required* The domain name you want to add. "www." prefixes are ignored for purposes of matching ranks, but will be stored as part of the domain name for future requests.
19
+ # @param engine_id [String] _Optional_ Comma separate list of search engine ids that you want to track for this domain. Defaults to '1,2,3' which is Google, Yahoo! and Bing
20
+ #
21
+
22
+ def self.add domain, engine_id = '1,2,3'
23
+ Raven.http.get '', { method: 'add_domain', domain: domain, engine_id: engine_id }
24
+ end
25
+
26
+ ##
27
+ # This request will return the available keywords for the domain provided.
28
+ #
29
+ # @param domain [String] *Required* The domain name you want results for. _Must match exactly_
30
+ #
31
+
32
+ def self.keywords domain
33
+ Raven.http.get '', { method: 'keywords', domain: domain }
34
+ end
35
+
36
+ ##
37
+ # This request will return the available keywords for the domain provided.
38
+ #
39
+ # @param domain [String] *Required* The domain name you want results for. _Must match exactly_
40
+ #
41
+
42
+ def self.keywords_with_tags domain
43
+ Raven.http.get '', { method: 'keywords_tags', domain: domain }
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,18 @@
1
+ module Raven
2
+
3
+ class Engines
4
+
5
+ ##
6
+ # Supported engines for Raven.
7
+ #
8
+ # @return [Array] Supported engines.
9
+ # @note Currently getting redirected to login for this endpoint
10
+ #
11
+
12
+ def self.all
13
+ Raven.http.get '', { method: 'engines' }
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,54 @@
1
+ module Raven
2
+
3
+ class Http # @private
4
+
5
+ attr_accessor :errors, :response, :success, :config
6
+
7
+ def initialize(_config)
8
+ @config, @errors, @success = _config, [], false
9
+ end
10
+
11
+ def get(path = '', params = {})
12
+ request 'get', "#{path}?#{RestClient::Payload.generate(build_params(params))}"
13
+ end
14
+
15
+ def post(path = '', params = {})
16
+ request 'post', path, build_params(params)
17
+ end
18
+
19
+ def build_params(params = {})
20
+ params.merge key: @config.api_key, format: 'json'
21
+ end
22
+
23
+ def request(http_verb, path, params = nil)
24
+ url = "#{@config.host}#{path}"
25
+ args = http_verb == 'post' ? [http_verb, url, params] : [http_verb, url]
26
+
27
+ response = RestClient.send *args do |res, req, raw_res|
28
+ body = raw_res.body
29
+ code = raw_res.code.to_i
30
+
31
+ self.response = body
32
+ self.errors = []
33
+
34
+ case code
35
+ when 200
36
+ begin
37
+ parsed = JSON.parse body
38
+ rescue JSON::ParserError => e
39
+ self.response = body
40
+ end
41
+ self.success = true
42
+ when 204
43
+ self.errors << RequestError.new('No Content', code, path, params)
44
+ else
45
+ self.errors << RequestError.new(body, code, path, params)
46
+ end
47
+
48
+ Response.new(self, code, path, params)
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,29 @@
1
+ module Raven
2
+
3
+ class Keyword
4
+
5
+ ##
6
+ # This request will add keyword to the domain provided.
7
+ #
8
+ # @param domain [String] *Required* - The domain you want the keyword to be added to.
9
+ # @param keyword [String] *Required* - The keyword you are adding.
10
+ #
11
+
12
+ def self.add domain, keyword
13
+ Raven.http.get '', { method: 'add_keyword', domain: domain, keyword: keyword }
14
+ end
15
+
16
+ ##
17
+ # This request will remove a keyword from the domain provided.
18
+ #
19
+ # @param domain [String] *Required* - The domain you want the keyword to be removed from.
20
+ # @param keyword [String] *Required* - The keyword you are removing.
21
+ #
22
+
23
+ def self.remove domain, keyword
24
+ Raven.http.get '', { method: 'remove_keyword', domain: domain, keyword: keyword }
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,17 @@
1
+ module Raven
2
+
3
+ class Profile
4
+
5
+ ##
6
+ # This request will return the name and billable keyword usage for the current profile.
7
+ #
8
+ # @return [Hash] Hash of profile information.
9
+ #
10
+
11
+ def self.info
12
+ Raven.http.get '', { method: 'profile_info' }
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,13 @@
1
+ module Raven
2
+
3
+ class RequestError
4
+
5
+ attr_reader :message, :code, :path, :params
6
+
7
+ def initialize(_message, _code, _path, _params) # @private
8
+ @message, @code, @path, @params = _message, _code, _path, _params
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,38 @@
1
+ module Raven
2
+
3
+ class Response
4
+
5
+ attr_reader :success, :body, :errors, :code, :path, :params
6
+
7
+ ##
8
+ # Initializing response object to be returned from API calls, used internally.
9
+ #
10
+
11
+ def initialize(http, _code, _path, _params) # @private
12
+ @success, @body, @errors = http.success, http.response, http.errors
13
+ @code, @path, @params = _code, _path, _params
14
+ end
15
+
16
+ ##
17
+ #
18
+ # Convenience method to determine if request was successfull or not
19
+ # @return [Boolean]
20
+
21
+ def success?
22
+ !!@success
23
+ end
24
+
25
+ ##
26
+ #
27
+ # Parses JSON body of request and returns a Hashie::Mash
28
+ # @return [Hashie::Mash]
29
+
30
+ def parsed_body
31
+ hash = JSON.parse(@body) rescue {}
32
+ return hash if hash.is_a?(Array)
33
+ Hashie::Mash.new hash
34
+ end
35
+
36
+ end
37
+
38
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rb_raven_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chavez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.7
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.6.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: hashie
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.2.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.7.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.7.1
78
+ - !ruby/object:Gem::Dependency
79
+ name: vcr
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 2.2.5
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 2.2.5
94
+ - !ruby/object:Gem::Dependency
95
+ name: webmock
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: 1.8.11
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 1.8.11
110
+ description: Wraps RavenTools API calls in a gem.
111
+ email: ''
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files:
115
+ - README.md
116
+ files:
117
+ - lib/raven.rb
118
+ - lib/rb_raven_api/config.rb
119
+ - lib/rb_raven_api/domain.rb
120
+ - lib/rb_raven_api/engines.rb
121
+ - lib/rb_raven_api/http.rb
122
+ - lib/rb_raven_api/keyword.rb
123
+ - lib/rb_raven_api/profile.rb
124
+ - lib/rb_raven_api/request_error.rb
125
+ - lib/rb_raven_api/response.rb
126
+ - lib/rb_raven_api.rb
127
+ - README.md
128
+ homepage: http://github.com/mtchavez/rb-raven-api
129
+ licenses: []
130
+ post_install_message:
131
+ rdoc_options:
132
+ - --charset=UTF-8 --main=README.md
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 1.8.23
150
+ signing_key:
151
+ specification_version: 3
152
+ summary: RavenTools API
153
+ test_files: []
154
+ has_rdoc: