blippex_api 1.0.0.pre.6
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 +15 -0
- data/.gitignore +21 -0
- data/.travis.yml +16 -0
- data/Gemfile +7 -0
- data/LICENSE +20 -0
- data/README.md +146 -0
- data/bin/blippex_api +2 -0
- data/blippex_api.gemspec +26 -0
- data/lib/blippex_api.rb +29 -0
- data/lib/blippex_api/client.rb +33 -0
- data/lib/blippex_api/client/info.rb +14 -0
- data/lib/blippex_api/client/rate_limit_status.rb +15 -0
- data/lib/blippex_api/client/search.rb +21 -0
- data/lib/blippex_api/configuration.rb +41 -0
- data/lib/blippex_api/connection.rb +31 -0
- data/lib/blippex_api/request.rb +50 -0
- data/lib/blippex_api/version.rb +3 -0
- data/lib/faraday/response/blippex_error.rb +26 -0
- data/lib/faraday/utils/utils.rb +26 -0
- data/spec/blippex_api_spec.rb +23 -0
- data/spec/helper.rb +19 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTE0NzZhODg2NjRjYmEwNTNjNDcyODIwNDVmOWNmODE5YWQ4ZTBiOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Mjk0ZmRlYTU0ODAxNGI1N2ZiOWI3ODNmN2E4MjEwMTA5NGIzNmRmZA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NTZkMDQyNmI3OTczOTBhNzE1NTY5ODA5YzhlNzU4ZDNkMGQyMWRlNThhODY1
|
10
|
+
M2YxNjE5NDc3NzJiMmY1OWRhZDI5NzU2M2E5ZDJlNWFmZTBmYWQ5OWEzNWMz
|
11
|
+
YzA5MWQ1MDY3MTFjNTg2NmY2NGIzNjBjZWRjYjFmNTdiZDZhZWM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NzFkZGM2OWM2MjI2YTM0MzczYjc4NmU5YzZjNTdhZTA2NGZjMjU3ZjBhOGQy
|
14
|
+
MjFjODdkNTk0NmEyNGZhMjI5ODAzNTA5ZjQ5NmI1YjcyOTk2OTc0ODA0YTZm
|
15
|
+
ODE0ZWI1NDUwZGM1NTRhN2UzZDc1MTNhZWM5NzczMmVhNDA3Y2Q=
|
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
.DS_Store
|
15
|
+
Gemfile.lock
|
16
|
+
report.html
|
17
|
+
|
18
|
+
# YARD artifacts
|
19
|
+
.yardoc
|
20
|
+
_yardoc
|
21
|
+
doc/
|
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.0.0
|
5
|
+
- 1.9.3
|
6
|
+
- 1.9.2
|
7
|
+
|
8
|
+
script: bundle exec rspec
|
9
|
+
|
10
|
+
deploy:
|
11
|
+
provider: rubygems
|
12
|
+
api_key:
|
13
|
+
secure: Y87RrmR7ZbZoZU9IfqCX9zuyQ3+47Xik68jQW9rr1LLuFFZhMhwz7+cBSm6g/3fnN8HMBPCavXnuqOZ6qlt7vtqLEik12e/cUPW5mzgLGafEkv6QYhWrIjl+tyIPyQvlAVm0+UyonBkkLKEa9pCdCVIgwQzqCW4wqG/HjiPOxzA=
|
14
|
+
gem: blippex_api
|
15
|
+
on:
|
16
|
+
repo: jonathanchrisp/blippex_api
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Jonathan Chrisp
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# blippex_api
|
2
|
+
A ruby wrapper for the blippex search engine made bythe people, forthe people.
|
3
|
+
|
4
|
+
You can find out more about the Blippex API [here](https://archify.atlassian.net/wiki/display/blippexAPI/api.blippex.org).
|
5
|
+
|
6
|
+
## Documentation
|
7
|
+
* Original documenation: <https://archify.atlassian.net/wiki/display/blippexAPI/api.blippex.org>
|
8
|
+
* Gem documentation: <http://rubydoc.info/gems/blippex_api>
|
9
|
+
|
10
|
+
## Getting Started
|
11
|
+
In order to be able to send API requests you'll first need to install the `blippex_api` gem.
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem install blippex_api
|
15
|
+
```
|
16
|
+
|
17
|
+
Once you have completed the steps above, you can now create an instance of a `BlippexAPI::Client`:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'blippex_api'
|
21
|
+
api = BlippexAPI::Client.new
|
22
|
+
```
|
23
|
+
|
24
|
+
If you now look at your `BlippexAPI` object instance it will be similar to the following:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
<BlippexAPI::Client:0x007fe9a23055f0
|
28
|
+
@adapter=:net_http,
|
29
|
+
@api_endpoint="https://api.blippex.org/",
|
30
|
+
@user_agent="BlippexAPI Ruby Gem 1.0.0">
|
31
|
+
```
|
32
|
+
|
33
|
+
## Example requests
|
34
|
+
Now that you have an `BlippexAPI::Client` instance you can now make requests.
|
35
|
+
|
36
|
+
### info endpoint
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
api.info
|
40
|
+
```
|
41
|
+
|
42
|
+
The response is returned within a `Hashie::Mash` instance.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
{
|
46
|
+
"total_page_count"=>5654101,
|
47
|
+
"total_pageview_count"=>8662559,
|
48
|
+
"yesterday_page_count"=>55708,
|
49
|
+
"yesterday_pageview_count"=>67842,
|
50
|
+
"search_count_history"=> [
|
51
|
+
{
|
52
|
+
"date"=>"2013-09-24T00:00:00+00:00",
|
53
|
+
"value"=>"83115"
|
54
|
+
},
|
55
|
+
{
|
56
|
+
"date"=>"2013-09-23T00:00:00+00:00",
|
57
|
+
"value"=>"70182"
|
58
|
+
}
|
59
|
+
]
|
60
|
+
}
|
61
|
+
```
|
62
|
+
|
63
|
+
### search endpoint
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
api.search :q => 'Lakers', :w => 20, :d => 2, :highlight => 1, :limit => 1, :offset => 1
|
67
|
+
```
|
68
|
+
|
69
|
+
As above, the response is returned within a `Hashie::Mash` instance.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
{
|
73
|
+
"request"=> {
|
74
|
+
"days"=>2,
|
75
|
+
"weight"=>20,
|
76
|
+
"limit"=>1,
|
77
|
+
"offset"=>1,
|
78
|
+
"query"=>"Lakers"
|
79
|
+
},
|
80
|
+
"total"=>31,
|
81
|
+
"hits_displayed"=>1,
|
82
|
+
"results"=> [
|
83
|
+
{
|
84
|
+
"_id"=>"1d431326999324b8eccb85b7399553f4",
|
85
|
+
"_source"=>"Blippex",
|
86
|
+
"url"=>"http://about.me/claresayas",
|
87
|
+
"last_seen_at"=>"2013-09-24T15:17:25-07:00",
|
88
|
+
"language"=>"en",
|
89
|
+
"title"=>"Clare Sayas (claresayas) on about.me",
|
90
|
+
"highlight"=>
|
91
|
+
" of the community managers for EdelmanSV.\nOn a mission to help entrepreuners find their voice and advance the field of public engagement.\n<mark>Lakers</mark> fan, film/tv enthusiast, relentless home",
|
92
|
+
"score"=> {
|
93
|
+
"score_raw_elasticsearch"=>0,
|
94
|
+
"score_raw_dwell"=>4.3298473876598,
|
95
|
+
"sum_time_spend"=>38,
|
96
|
+
"sum_visits"=>3,
|
97
|
+
"score_clean_elasticsearch"=>0,
|
98
|
+
"score_clean_dwell"=>0.86449725527946,
|
99
|
+
"score_final"=>0.69159780422356
|
100
|
+
}
|
101
|
+
}
|
102
|
+
],
|
103
|
+
"total_pages_in_db"=>5687567
|
104
|
+
}
|
105
|
+
|
106
|
+
```
|
107
|
+
|
108
|
+
### ratelimitstatus endpoint
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
api.rate_limit_status
|
112
|
+
```
|
113
|
+
|
114
|
+
As above, the response is returned within a `Hashie::Mash` instance.
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
{
|
118
|
+
"ip"=>"00.0.000.00",
|
119
|
+
"data"=> {
|
120
|
+
"info"=> {
|
121
|
+
"remaining"=>997,
|
122
|
+
"reset"=>1380136296,
|
123
|
+
"limit"=>1000
|
124
|
+
},
|
125
|
+
"search"=> {
|
126
|
+
"remaining"=>3587,
|
127
|
+
"reset"=>1380136296,
|
128
|
+
"limit"=>3600
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
```
|
133
|
+
|
134
|
+
To find out more information about `Hashie` please visit the following link: <https://github.com/intridea/hashie>.
|
135
|
+
|
136
|
+
## Tests
|
137
|
+
There are a number of unit tests which are included as part of this project, please run:
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
rspec spec
|
141
|
+
```
|
142
|
+
|
143
|
+
Please note that a number of tests still need to be added so I don't currently have complete coverage, subject to workload these will be slowly added over the next few months.
|
144
|
+
|
145
|
+
## Feedback
|
146
|
+
I would be more than happy to recieve feedback, please email me at: jonathan.chrisp@gmail.com.
|
data/bin/blippex_api
ADDED
data/blippex_api.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/lib/blippex_api/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'blippex_api'
|
5
|
+
s.version = BlippexAPI::VERSION
|
6
|
+
s.version = BlippexAPI::VERSION + ".pre.#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV['TRAVIS']
|
7
|
+
s.date = '2013-09-25'
|
8
|
+
s.summary = 'Blippex API ruby wrapper'
|
9
|
+
s.description = 'A ruby wrapper for the blippex search engine API made bythe people, forthe people'
|
10
|
+
s.author = 'Jonathan Chrisp'
|
11
|
+
s.email = 'jonathan@brandwatch.com'
|
12
|
+
s.license = 'MIT'
|
13
|
+
s.homepage = 'https://github.com/jonathanchrisp/blippex_api'
|
14
|
+
s.required_ruby_version = ">= 1.9.2"
|
15
|
+
|
16
|
+
s.add_development_dependency 'rspec', '~> 2.13.0'
|
17
|
+
|
18
|
+
s.add_runtime_dependency 'faraday', '~> 0.8.7'
|
19
|
+
s.add_runtime_dependency 'faraday_middleware', '~> 0.9.0'
|
20
|
+
s.add_runtime_dependency 'hashie', '~> 2.0.5'
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
25
|
+
s.require_paths = ['lib']
|
26
|
+
end
|
data/lib/blippex_api.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'blippex_api/version'
|
2
|
+
require 'blippex_api/configuration'
|
3
|
+
require 'blippex_api/client'
|
4
|
+
|
5
|
+
# BlippexAPI namespace module
|
6
|
+
module BlippexAPI
|
7
|
+
extend Configuration
|
8
|
+
class << self
|
9
|
+
|
10
|
+
# Alias for BlippexAPI::Client.new
|
11
|
+
#
|
12
|
+
# @return [BlippexAPI::Client]
|
13
|
+
def new opts={}
|
14
|
+
BlippexAPI::Client.new opts
|
15
|
+
end
|
16
|
+
|
17
|
+
# Delegate to BlippexAPI::Client.new
|
18
|
+
def method_missing method, *args, &block
|
19
|
+
return super unless new.respond_to? method
|
20
|
+
new.send method, *args, &block
|
21
|
+
end
|
22
|
+
|
23
|
+
# Check if method responds_to?
|
24
|
+
def respond_to? method, include_private=false
|
25
|
+
new.respond_to?(method, include_private) || super(method, include_private)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'blippex_api/connection'
|
2
|
+
require 'blippex_api/request'
|
3
|
+
|
4
|
+
require 'blippex_api/client/info'
|
5
|
+
require 'blippex_api/client/search'
|
6
|
+
require 'blippex_api/client/rate_limit_status'
|
7
|
+
|
8
|
+
module BlippexAPI
|
9
|
+
# Client class to create BlippexAPI instances
|
10
|
+
class Client
|
11
|
+
|
12
|
+
attr_accessor *Configuration::OPTION_KEYS
|
13
|
+
|
14
|
+
def initialize opts={}
|
15
|
+
# Merge opts
|
16
|
+
opts = BlippexAPI.options.merge opts
|
17
|
+
|
18
|
+
# Create instance variables
|
19
|
+
Configuration::OPTION_KEYS.each do |k|
|
20
|
+
send "#{k}=", opts[k]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
include BlippexAPI::Connection
|
25
|
+
include BlippexAPI::Request
|
26
|
+
|
27
|
+
# API endpoints
|
28
|
+
include BlippexAPI::Client::Info
|
29
|
+
include BlippexAPI::Client::Search
|
30
|
+
include BlippexAPI::Client::RateLimitStatus
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module BlippexAPI
|
2
|
+
class Client
|
3
|
+
module RateLimitStatus
|
4
|
+
|
5
|
+
# Get request limit status
|
6
|
+
#
|
7
|
+
# @option opts [String] callback the response will use the JSONP format with a callback of the given name
|
8
|
+
# @return [Hashie::Mash] Hash containing the response
|
9
|
+
def rate_limit_status opts={}
|
10
|
+
get 'ratelimitstatus', opts
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module BlippexAPI
|
2
|
+
class Client
|
3
|
+
module Search
|
4
|
+
|
5
|
+
# Get search data
|
6
|
+
#
|
7
|
+
# @param opts [String] q search term
|
8
|
+
# @option opts [Integer] w the scoring of the searchterms has on the ranking of the search result in percent
|
9
|
+
# @option opts [Integer] d the number of days the search should go back
|
10
|
+
# @option opts [Integer] highlight highlight=1 if you want to add an excerpt of the text with a the highlighted search terms
|
11
|
+
# @option opts [Integer] limit this is the number of individual objects that are returned (maximum 100)
|
12
|
+
# @option opts [Integer] offset this offsets the start of the results by the number specified
|
13
|
+
# @option opts [String] callback the response will use the JSONP format with a callback of the given name
|
14
|
+
# @return [Hashie::Mash] Hash containing the response
|
15
|
+
def search opts={}
|
16
|
+
get 'search', opts
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module BlippexAPI
|
4
|
+
# Configuration module to set default and custom client credentials
|
5
|
+
module Configuration
|
6
|
+
|
7
|
+
OPTION_KEYS = [
|
8
|
+
'adapter',
|
9
|
+
'api_endpoint',
|
10
|
+
'user_agent'
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
DEFAULT_ADAPTER = Faraday.default_adapter
|
14
|
+
DEFAULT_API_ENDPOINT = 'https://api.blippex.org/'
|
15
|
+
DEFAULT_USER_AGENT = "BlippexAPI Ruby Gem #{BlippexAPI::VERSION}".freeze
|
16
|
+
|
17
|
+
attr_accessor *OPTION_KEYS
|
18
|
+
|
19
|
+
# Extend hook
|
20
|
+
def self.extended(base)
|
21
|
+
base.reset
|
22
|
+
end
|
23
|
+
|
24
|
+
# Set configuration options using a block
|
25
|
+
def configure
|
26
|
+
yield self
|
27
|
+
end
|
28
|
+
|
29
|
+
# Convert option_keys to hash and return
|
30
|
+
def options
|
31
|
+
OPTION_KEYS.inject({}){|o,k|o.merge!(k => send(k))}
|
32
|
+
end
|
33
|
+
|
34
|
+
# Reset the configuration options
|
35
|
+
def reset
|
36
|
+
self.adapter = DEFAULT_ADAPTER
|
37
|
+
self.user_agent = DEFAULT_USER_AGENT
|
38
|
+
self.api_endpoint = DEFAULT_API_ENDPOINT
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
require 'faraday/utils/utils'
|
3
|
+
|
4
|
+
module BlippexAPI
|
5
|
+
# Connection module to handle requests
|
6
|
+
module Connection
|
7
|
+
private
|
8
|
+
|
9
|
+
# Create a connection to send request
|
10
|
+
def connection opts={}
|
11
|
+
connection = Faraday.new(opts) do |conn|
|
12
|
+
|
13
|
+
if opts[:force_urlencoded]
|
14
|
+
conn.request :url_encoded
|
15
|
+
else
|
16
|
+
conn.request :json
|
17
|
+
end
|
18
|
+
|
19
|
+
conn.request :json
|
20
|
+
conn.use FaradayMiddleware::FollowRedirects
|
21
|
+
conn.use FaradayMiddleware::Mashify
|
22
|
+
conn.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
|
23
|
+
conn.adapter adapter
|
24
|
+
end
|
25
|
+
|
26
|
+
connection.headers[:user_agent] = user_agent
|
27
|
+
connection
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
3
|
+
module BlippexAPI
|
4
|
+
# Request module to handle all requests to API
|
5
|
+
module Request
|
6
|
+
|
7
|
+
# Perform a get request
|
8
|
+
#
|
9
|
+
# @param path [String] URL path to send request
|
10
|
+
# @param opts [Hash] Request parameters
|
11
|
+
# @return [Hashie::Mash] Response body
|
12
|
+
def get path, opts={}
|
13
|
+
request(:get, path, opts).body
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
# Sets connection options
|
19
|
+
#
|
20
|
+
# @param opts [Hash] hash of opts passed
|
21
|
+
# @return [Hash] connection options
|
22
|
+
def connection_options opts
|
23
|
+
{
|
24
|
+
:headers => {
|
25
|
+
:user_agent => user_agent
|
26
|
+
},
|
27
|
+
:force_urlencoded => opts.delete(:force_urlencoded) || false,
|
28
|
+
:url => api_endpoint
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
# Perform a request
|
33
|
+
#
|
34
|
+
# @param method [String] Type of request path
|
35
|
+
# @param path [String] URL path to send request
|
36
|
+
# @param opts [Hash] Request parameters
|
37
|
+
# @return [Hashie::Mash] Response
|
38
|
+
def request method, path, opts={}
|
39
|
+
conn_options = connection_options opts
|
40
|
+
response = connection(conn_options).send(method) do |request|
|
41
|
+
case method
|
42
|
+
when :get
|
43
|
+
request.url path, opts
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
response
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module Faraday
|
5
|
+
# Response::BlippexAPI class to raise custom faraday middleware errors
|
6
|
+
class Response::BlippexAPI < Response::Middleware
|
7
|
+
ERROR_MAP = {
|
8
|
+
400 => BlippexAPI::BadRequest,
|
9
|
+
401 => BlippexAPI::Unauthorized,
|
10
|
+
403 => BlippexAPI::Forbidden,
|
11
|
+
404 => BlippexAPI::NotFound,
|
12
|
+
406 => BlippexAPI::NotAcceptable,
|
13
|
+
422 => BlippexAPI::UnprocessableEntity,
|
14
|
+
429 => BlippexAPI::TooManyRequests,
|
15
|
+
500 => BlippexAPI::InternalServerError,
|
16
|
+
501 => BlippexAPI::NotImplemented,
|
17
|
+
502 => BlippexAPI::BadGateway,
|
18
|
+
503 => BlippexAPI::ServiceUnavailable
|
19
|
+
}
|
20
|
+
|
21
|
+
def on_complete(response)
|
22
|
+
key = response[:status].to_i
|
23
|
+
raise ERROR_MAP[key].new(response) if ERROR_MAP.has_key? key
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# TODO: Remove this patch once latest faraday rc has been released
|
4
|
+
# https://github.com/lostisland/faraday/issues/182#issuecomment-19518167
|
5
|
+
module Faraday
|
6
|
+
# Overriding Faraday::Utils module build_nested_query method
|
7
|
+
module Utils
|
8
|
+
def build_nested_query(value, prefix = nil)
|
9
|
+
case value
|
10
|
+
when Array
|
11
|
+
value.map { |v| build_nested_query(v, "#{prefix}") }.join("&")
|
12
|
+
#value.map { |v| build_nested_query(v, "#{prefix}%5B%5D") }.join("&")
|
13
|
+
when Hash
|
14
|
+
value.map { |k, v|
|
15
|
+
build_nested_query(v, prefix ? "#{prefix}#{escape(k)}" : escape(k))
|
16
|
+
#build_nested_query(v, prefix ? "#{prefix}%5B#{escape(k)}%5D" : escape(k))
|
17
|
+
}.join("&")
|
18
|
+
when NilClass
|
19
|
+
prefix
|
20
|
+
else
|
21
|
+
raise ArgumentError, "value must be a Hash" if prefix.nil?
|
22
|
+
"#{prefix}=#{escape(value)}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe BlippexAPI do
|
4
|
+
|
5
|
+
describe 'when called' do
|
6
|
+
it 'should be an instance of Module' do
|
7
|
+
BlippexAPI.should be_an_instance_of Module
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.new' do
|
12
|
+
it 'is a BlippexAPI::Client' do
|
13
|
+
expect(BlippexAPI.new).to be_a BlippexAPI::Client
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.respond_to?' do
|
18
|
+
it 'returns true if new method exists' do
|
19
|
+
expect(BlippexAPI.respond_to?(:new, true)).to eq(true)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
require 'simplecov'
|
3
|
+
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
Coveralls::SimpleCov::Formatter,
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
]
|
8
|
+
|
9
|
+
SimpleCov.start
|
10
|
+
require 'blippex_api'
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.color_enabled = true
|
14
|
+
config.formatter = :documentation
|
15
|
+
end
|
16
|
+
|
17
|
+
def fixture_path
|
18
|
+
File.expand_path("../fixtures", __FILE__)
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blippex_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Chrisp
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.13.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.13.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.8.7
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday_middleware
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.9.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hashie
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.5
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.5
|
69
|
+
description: A ruby wrapper for the blippex search engine API made bythe people, forthe
|
70
|
+
people
|
71
|
+
email: jonathan@brandwatch.com
|
72
|
+
executables:
|
73
|
+
- blippex_api
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .travis.yml
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- bin/blippex_api
|
83
|
+
- blippex_api.gemspec
|
84
|
+
- lib/blippex_api.rb
|
85
|
+
- lib/blippex_api/client.rb
|
86
|
+
- lib/blippex_api/client/info.rb
|
87
|
+
- lib/blippex_api/client/rate_limit_status.rb
|
88
|
+
- lib/blippex_api/client/search.rb
|
89
|
+
- lib/blippex_api/configuration.rb
|
90
|
+
- lib/blippex_api/connection.rb
|
91
|
+
- lib/blippex_api/request.rb
|
92
|
+
- lib/blippex_api/version.rb
|
93
|
+
- lib/faraday/response/blippex_error.rb
|
94
|
+
- lib/faraday/utils/utils.rb
|
95
|
+
- spec/blippex_api_spec.rb
|
96
|
+
- spec/helper.rb
|
97
|
+
homepage: https://github.com/jonathanchrisp/blippex_api
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.9.2
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ! '>'
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 1.3.1
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.0.3
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Blippex API ruby wrapper
|
121
|
+
test_files:
|
122
|
+
- spec/blippex_api_spec.rb
|
123
|
+
- spec/helper.rb
|