panlex_client 0.2.0 → 0.3.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.
- data/README.md +8 -7
- data/lib/panlex_client/panlex_client.rb +7 -2
- data/panlex_client.spec +3 -1
- data/spec/lib/panlex_client/panlex_client_spec.rb +18 -0
- data/spec/spec_helper.rb +1 -0
- metadata +20 -2
data/README.md
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
# panlex\_client
|
2
|
-
|
2
|
+
|
3
|
+
Simple Ruby client for the [public API](http://dev.panlex.org/api/) of the [PanLex Database](http://panlex.org). It uses [rest-client](https://github.com/adamwiggins/rest-client) gem.
|
3
4
|
|
4
5
|
## Usage
|
5
6
|
|
6
|
-
Right now, there is just a `PanlexClient` module with only one `query` method
|
7
|
+
Right now, there is just a `PanlexClient` module with only one `query` method wich takes two arguments: the URL parameter and the request body. It returns PanLex API response parsed to a Hash or raises an exception with the response in it.
|
7
8
|
|
8
9
|
```ruby
|
9
10
|
require 'panlex_client'
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
if response['status'] == 'OK' then
|
12
|
+
begin
|
13
|
+
response = PanlexClient.query 'lv', { :indent => true, :limit => 2 }
|
14
14
|
response['result'].each do |language|
|
15
|
-
|
15
|
+
puts language['tt']
|
16
16
|
end
|
17
|
+
rescue RestClient::ExceptionWithResponse => e
|
18
|
+
puts JSON.parse(e.response)['message']
|
17
19
|
end
|
18
|
-
|
19
20
|
```
|
20
21
|
|
21
22
|
## Relase Policy
|
@@ -8,8 +8,13 @@ module PanlexClient
|
|
8
8
|
# @param param [String] {http://dev.panlex.org/api/#urlparam PanLex API URL parameter}
|
9
9
|
# @param body [#to_json] The request body which includes the query parameters. Look at the {http://dev.panlex.org/api/#globalparam global optional parameter} and the specifics for each URL parameter
|
10
10
|
# @return [Hash] {http://dev.panlex.org/api/#globalparam PanLex API response}
|
11
|
+
# @raise [RestClient::ExceptionWithResponse] if there is an error in the response. You can use e.response to access the PanLex API error response
|
11
12
|
def self.query(param, body)
|
12
|
-
|
13
|
-
|
13
|
+
begin
|
14
|
+
response = RestClient.post API_URL+param, body.to_json, { 'content-type' => :json, :accept => :json, 'accept-encoding' => 'gzip' }
|
15
|
+
JSON.parse(response)
|
16
|
+
rescue RestClient::ExceptionWithResponse => e
|
17
|
+
raise e
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
data/panlex_client.spec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'panlex_client'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.3.0'
|
4
4
|
s.summary = 'Client for the PanLex database public API'
|
5
5
|
s.description = 'https://github.com/laMarciana/panlex_client/'
|
6
6
|
s.license = 'GPL3'
|
@@ -12,4 +12,6 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.add_runtime_dependency "rest-client", "~>1.6"
|
13
13
|
s.add_runtime_dependency "yard", "~>0.8"
|
14
14
|
s.add_runtime_dependency "redcarpet", "~>2.2"
|
15
|
+
|
16
|
+
s.add_development_dependency "rspec", "~>2.13"
|
15
17
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PanlexClient do
|
4
|
+
describe "::query" do
|
5
|
+
context "when the request is successfully" do
|
6
|
+
it "should return PanLex response parsed in a Hash" do
|
7
|
+
response = PanlexClient.query 'lv', { limit: 1 }
|
8
|
+
response.should be_an_instance_of Hash
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when the request is not successfully" do
|
13
|
+
it "should raise an exception with the response" do
|
14
|
+
expect { PanlexClient.query 'foo', {} }.to raise_error RestClient::ExceptionWithResponse
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative '../lib/panlex_client'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: panlex_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '2.2'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.13'
|
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: '2.13'
|
62
78
|
description: https://github.com/laMarciana/panlex_client/
|
63
79
|
email: marc@lamarciana.com
|
64
80
|
executables: []
|
@@ -72,6 +88,8 @@ files:
|
|
72
88
|
- lib/panlex_client.rb
|
73
89
|
- lib/panlex_client/panlex_client.rb
|
74
90
|
- panlex_client.spec
|
91
|
+
- spec/lib/panlex_client/panlex_client_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
75
93
|
homepage: https://github.com/laMarciana/panlex_client/
|
76
94
|
licenses:
|
77
95
|
- GPL3
|