seekr-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d2702b21ccb5e5c2a221ebe11a1928e8edb4006c
4
+ data.tar.gz: 6737c33c134d4fc089707c9e9cd5aba017748707
5
+ SHA512:
6
+ metadata.gz: 34306866f588550c3c78f71101e94c785cdf1c1d5437140e2904233ec4e5a4b6ce91682018f5e4139a50ad1b52abd7c5e95dbecfb66d8455d1974c443f3e774d
7
+ data.tar.gz: fd71d4da8b550e7e3c92d41703d8017b507a981b5f2b9740d6e0c3e9c9afa71d5b91463bfcd2a8b2b01d5d47ce5ea1991c45286eb956d5dbffc2bea6eb938fa8
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1 @@
1
+ sekr-ruby
@@ -0,0 +1 @@
1
+ 2.1.4
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.2.0"
4
+ - "1.9.3"
5
+
6
+ addons:
7
+ code_climate:
8
+ repo_token: 39dd34a749a1e3a5e4a1e08f97d454ee71fb2b079f8a447447d27e8c1ea1867d
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in seekr-ruby.gemspec
4
+ gemspec
5
+
6
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Rodrigo Pinto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Rodrigo Pinto
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.
@@ -0,0 +1,202 @@
1
+ # Seekr::Ruby
2
+
3
+ [![Build Status][travis_badge]][travis]
4
+ [![Code Climate][codeclimate_badge]][codeclimate]
5
+ [![Test Coverage][test_badge]][test]
6
+
7
+ Ruby client for [Seekr Monitor][seekr] API.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'seekr-ruby'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install seekr-ruby
24
+
25
+ ## Usage
26
+
27
+ ### Configure API keys
28
+
29
+ Create a file `config/initializers/seekr.rb` and add:
30
+
31
+ ```ruby
32
+ Seekr.configure do |config|
33
+ config.api_key = "<API-KEY>"
34
+ config.api_secret = "<API-SECRET>"
35
+ end
36
+ ```
37
+
38
+ ### Searching for monitors
39
+
40
+ Run:
41
+
42
+ ```ruby
43
+ monitor = Seekr::Monitor.new
44
+ monitor.all
45
+ ```
46
+
47
+ It results:
48
+
49
+ ```json
50
+ {
51
+ "response": {
52
+ "status": "200 OK",
53
+ "code": 200
54
+ },
55
+ "searches": [
56
+ {
57
+ "id": 1,
58
+ "name": "Monitor one",
59
+ "search_results": 1243,
60
+ "search_terms": 2,
61
+ "tags": 7,
62
+ "medias": 3,
63
+ "active": true,
64
+ "sentiment_analysis": false
65
+ },
66
+ {
67
+ "id": 2,
68
+ "name": "Monitor two",
69
+ "search_results": 546,
70
+ "search_terms": 5,
71
+ "tags": 2,
72
+ "medias": 0,
73
+ "active": false,
74
+ "sentiment_analysis": false
75
+ }
76
+ ]
77
+ }
78
+
79
+ ```
80
+
81
+ ### Searching for a specific monitor
82
+
83
+ Run:
84
+
85
+ ```ruby
86
+ monitor = Seekr::Monitor.new
87
+ monitor.find(9999)
88
+ ```
89
+
90
+ It results:
91
+
92
+ ```json
93
+ {
94
+ "response": {
95
+ "status": "200 OK",
96
+ "code": 200
97
+ },
98
+ "search": {
99
+ "id": 11111,
100
+ "name": "[Dashboard] Cards",
101
+ "start_date": "01/11/2013",
102
+ "search_results": 10641,
103
+ "search_terms": [
104
+ {
105
+ "term": "Some Term",
106
+ "id": 1
107
+ },
108
+ {
109
+ "term": "some term",
110
+ "id": 2
111
+ }
112
+ ],
113
+ "tags": 10,
114
+ "medias": 4,
115
+ "active": false,
116
+ "sentiment_analysis": true
117
+ }
118
+ }
119
+ ```
120
+ ### Searching for tags of a monitor
121
+
122
+ Run:
123
+
124
+ ```ruby
125
+ monitor = Seekr::Monitor.new
126
+ monitor.tags(9999)
127
+ ```
128
+
129
+ It results:
130
+
131
+ ```json
132
+ {
133
+ "response": {
134
+ "status": "200 OK",
135
+ "code": 200
136
+ },
137
+
138
+ "tags": [
139
+ {
140
+ "id": 1,
141
+ "name": "Awesome Tag",
142
+ "search_results": 53
143
+ },
144
+
145
+ {
146
+ "id": 2,
147
+ "name": "Another Tag",
148
+ "search_results": 37
149
+ }
150
+ ]
151
+ }
152
+ ```
153
+
154
+ ### Report
155
+
156
+ #### General report
157
+
158
+ Run:
159
+
160
+ ```ruby
161
+ report = Seekr::Report.new(9999)
162
+ report.general
163
+ ```
164
+
165
+ It results:
166
+
167
+ ```json
168
+ {
169
+ "response": {
170
+ "status": "200 OK",
171
+ "code": 200
172
+ },
173
+ "report": {
174
+ "total": 2483,
175
+ "positive": 847,
176
+ "neutral": 1156,
177
+ "negative": 480,
178
+ "positive_perc": 34.4,
179
+ "neutral_perc": 46.3,
180
+ "negative_perc": 19.3
181
+ }
182
+ }
183
+ ```
184
+
185
+ ## Contributing
186
+
187
+ 1. Fork it ( https://github.com/rodrigopinto/seekr-ruby/fork )
188
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
189
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
190
+ 4. Push to the branch (`git push origin my-new-feature`)
191
+ 5. Create a new Pull Request
192
+
193
+ [travis]: https://travis-ci.org/rodrigopinto/seekr-ruby
194
+ [travis_badge]: https://travis-ci.org/rodrigopinto/seekr-ruby.svg?branch=master
195
+
196
+ [codeclimate]: https://codeclimate.com/github/rodrigopinto/seekr-ruby
197
+ [codeclimate_badge]: https://codeclimate.com/github/rodrigopinto/seekr-ruby/badges/gpa.svg
198
+
199
+ [test]: https://codeclimate.com/github/rodrigopinto/seekr-ruby
200
+ [test_badge]:https://codeclimate.com/github/rodrigopinto/seekr-ruby/badges/coverage.svg
201
+
202
+ [seekr]: http://seekr.com.br/
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+
9
+ rescue LoadError
10
+ # no rspec available
11
+ end
@@ -0,0 +1,34 @@
1
+ require "seekr/client"
2
+ require "seekr/configuration"
3
+ require "seekr/errors"
4
+ require "seekr/monitor"
5
+ require "seekr/occurrence"
6
+ require "seekr/report"
7
+ require "seekr/version"
8
+
9
+ require 'active_support/core_ext/time'
10
+
11
+ Time.zone = "Brasilia"
12
+
13
+ module Seekr
14
+
15
+ def self.configure(&block)
16
+ yield configuration
17
+ end
18
+
19
+ def self.configuration
20
+ @configuration ||= Seekr::Configuration.new
21
+ end
22
+
23
+ def self.api_key
24
+ configuration.api_key
25
+ end
26
+
27
+ def self.api_secret
28
+ configuration.api_secret
29
+ end
30
+
31
+ def self.reset
32
+ @configuration = nil
33
+ end
34
+ end
@@ -0,0 +1,40 @@
1
+ require 'rest-client'
2
+
3
+ module Seekr
4
+ module Client
5
+
6
+ BASE_URL = "http://monitoramento.seekr.com.br/api"
7
+
8
+ def get(method, params={})
9
+ url = build_url(method, params)
10
+ _get(url)
11
+ end
12
+
13
+ private
14
+ def _get(url)
15
+ RestClient.get url do |response, request, result, &block|
16
+ case response.code
17
+ when 200
18
+ response
19
+ when 403
20
+ raise Seekr::HTTPForbidden
21
+ end
22
+ end
23
+ end
24
+
25
+ def build_url(method, params={})
26
+ query_params = default_params.merge(params).to_param
27
+ "#{BASE_URL}#{method}.json?#{query_params}"
28
+ end
29
+
30
+ def default_params
31
+ timestamp = Time.zone.now.to_i
32
+ hash = Digest::SHA1.hexdigest("#{Seekr.api_secret}#{timestamp}")
33
+ {
34
+ key: Seekr.api_key,
35
+ ts: timestamp,
36
+ hash: hash
37
+ }
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,6 @@
1
+ module Seekr
2
+ class Configuration
3
+ attr_accessor :api_key
4
+ attr_accessor :api_secret
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ module Seekr
2
+ class Error < StandardError; end
3
+ class HTTPForbidden < Error; end
4
+ end
@@ -0,0 +1,17 @@
1
+ module Seekr
2
+ class Monitor
3
+ include Seekr::Client
4
+
5
+ def all
6
+ get("/searches")
7
+ end
8
+
9
+ def find(id)
10
+ get("/search", search_id: id)
11
+ end
12
+
13
+ def tags(id)
14
+ get("/tags", search_id: id)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module Seekr
2
+ class Occurrence
3
+ include Seekr::Client
4
+
5
+ def find_for(monitor_id, options = {})
6
+ params = { search_id: monitor_id, per_page: 100 }.merge(options)
7
+ get("/search_results", params)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,39 @@
1
+ module Seekr
2
+ class Report
3
+ include Seekr::Client
4
+
5
+ def initialize(monitor_id)
6
+ @monitor_id = monitor_id
7
+ end
8
+
9
+ def general(filters={})
10
+ fetch("/report", filters)
11
+ end
12
+
13
+ def by_cities(filters={})
14
+ fetch("/report_cities", filters)
15
+ end
16
+
17
+ def by_tags(filters={})
18
+ fetch("/report_tags", filters)
19
+ end
20
+
21
+ def by_states(filters={})
22
+ fetch("/report_states", filters)
23
+ end
24
+
25
+ def by_words(filters={})
26
+ fetch("/report_words", filters)
27
+ end
28
+
29
+ def by_people(filters={})
30
+ fetch("/report_users", filters)
31
+ end
32
+
33
+ private
34
+ def fetch(report, filters)
35
+ filters.merge!({ search_id: @monitor_id })
36
+ get(report, filters)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Seekr
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seekr-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rodrigo Pinto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.7.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.20.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.20.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: sinatra
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 1.4.5
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.4.5
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.10.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.10.1
125
+ description: Ruby client for Seekr Monitor API.
126
+ email:
127
+ - rodrigopqn@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".ruby-gemset"
134
+ - ".ruby-version"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - LICENSE
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - lib/seekr.rb
142
+ - lib/seekr/client.rb
143
+ - lib/seekr/configuration.rb
144
+ - lib/seekr/errors.rb
145
+ - lib/seekr/monitor.rb
146
+ - lib/seekr/occurrence.rb
147
+ - lib/seekr/report.rb
148
+ - lib/seekr/version.rb
149
+ homepage: http://github.com/rodrigopinto/seekr-ruby
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.4.2
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Ruby client for Seekr Monitor API.
173
+ test_files: []