popit 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -14
- data/lib/popit.rb +19 -15
- data/lib/popit/version.rb +1 -1
- data/spec/popit_spec.rb +8 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e0f5c6b92de48b6576028e879ce2ae23b648cbb
|
4
|
+
data.tar.gz: a178baf6cc337d0c44be75e73cff15aabafbf9e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91081f9cd938df6f9672cf45770e53007bea1067152d9e243d4e1ce5907840579dd68a092ada1cc6e32a7ef58fa03c0f1e8a6238bc9a18f14385f04a4b575274
|
7
|
+
data.tar.gz: 72ed49a72f1890dbc10bfd1cbd03a8197376e1dda7b85d7305d033cde8416b01b3a886fdfdad88262061ff5986ae692d018ed1f33d70151ca4a2f5f542ade131
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ require 'popit'
|
|
22
22
|
Then, create an API client for PopIt:
|
23
23
|
|
24
24
|
```ruby
|
25
|
-
api = PopIt.new
|
25
|
+
api = PopIt.new(:instance_name => 'demo')
|
26
26
|
```
|
27
27
|
|
28
28
|
You can pass these options to `PopIt.new`:
|
@@ -40,47 +40,55 @@ More documentation at [RubyDoc.info](http://rdoc.info/gems/popit/PopIt).
|
|
40
40
|
|
41
41
|
### Read
|
42
42
|
|
43
|
-
Get
|
43
|
+
Get one page of people (default 30 per page):
|
44
44
|
|
45
45
|
```ruby
|
46
46
|
api.persons.get
|
47
47
|
```
|
48
48
|
|
49
|
+
Get a different number of people per page (maximum 100 per page):
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
api.persons.get(:per_page => 100)
|
53
|
+
```
|
54
|
+
|
55
|
+
Get another page of people:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
api.persons.get(:page => 2)
|
59
|
+
```
|
60
|
+
|
49
61
|
Get one person:
|
50
62
|
|
51
63
|
```ruby
|
52
64
|
api.persons('47cc67093475061e3d95369d').get
|
53
65
|
```
|
54
66
|
|
55
|
-
|
56
|
-
|
57
|
-
* people by slug, name or summary
|
58
|
-
* organizations by slug or name
|
59
|
-
* memberships by title, person or organization
|
67
|
+
### Search
|
60
68
|
|
61
|
-
|
69
|
+
Read the [PopIt API documentation](http://popit.mysociety.org/docs/api/search) for details.
|
62
70
|
|
63
71
|
```ruby
|
64
|
-
api.
|
72
|
+
api.search.persons.get(:q => 'name:"John Doe"')
|
65
73
|
```
|
66
74
|
|
67
75
|
### Create
|
68
76
|
|
69
77
|
```ruby
|
70
|
-
response = api.
|
78
|
+
response = api.persons.post(:name => 'John Doe')
|
71
79
|
id = response['id']
|
72
80
|
```
|
73
81
|
|
74
82
|
### Update
|
75
83
|
|
76
84
|
```ruby
|
77
|
-
api.
|
85
|
+
api.persons(id).put(:id => id, :name => 'Jane Doe')
|
78
86
|
```
|
79
87
|
|
80
88
|
### Delete
|
81
89
|
|
82
90
|
```ruby
|
83
|
-
success = api.
|
91
|
+
success = api.persons(id).delete
|
84
92
|
```
|
85
93
|
|
86
94
|
## Error Handling
|
@@ -91,8 +99,8 @@ The exception's message will be the same as from the PopIt API.
|
|
91
99
|
|
92
100
|
```ruby
|
93
101
|
require 'popit'
|
94
|
-
api = PopIt.new
|
95
|
-
api.
|
102
|
+
api = PopIt.new(:instance_name => 'demo')
|
103
|
+
api.persons.get('foo') # raises PopIt::PageNotFound with "page not found"
|
96
104
|
```
|
97
105
|
|
98
106
|
## Running Tests
|
data/lib/popit.rb
CHANGED
@@ -49,7 +49,7 @@ class PopIt
|
|
49
49
|
# @option opts [String] :user a user name
|
50
50
|
# @option opts [String] :password the user's password
|
51
51
|
def initialize(opts = {})
|
52
|
-
unless opts.has_key?
|
52
|
+
unless opts.has_key?(:instance_name)
|
53
53
|
raise ArgumentError, 'Missing key :instance_name'
|
54
54
|
end
|
55
55
|
|
@@ -67,7 +67,7 @@ class PopIt
|
|
67
67
|
# @param [Hash] opts key-value pairs for the query string
|
68
68
|
# @return the JSON response from the server
|
69
69
|
def get(path, opts = {})
|
70
|
-
request
|
70
|
+
request(:get, path, opts)
|
71
71
|
end
|
72
72
|
|
73
73
|
# Sends a POST request.
|
@@ -76,7 +76,7 @@ class PopIt
|
|
76
76
|
# @param [Hash] opts key-value pairs for the message body
|
77
77
|
# @return the JSON response from the server
|
78
78
|
def post(path, opts = {})
|
79
|
-
request
|
79
|
+
request(:post, path, opts)
|
80
80
|
end
|
81
81
|
|
82
82
|
# Sends a PUT request.
|
@@ -85,7 +85,7 @@ class PopIt
|
|
85
85
|
# @param [Hash] opts key-value pairs for the message body
|
86
86
|
# @return [nil] nothing
|
87
87
|
def put(path, opts = {})
|
88
|
-
request
|
88
|
+
request(:put, path, opts)
|
89
89
|
end
|
90
90
|
|
91
91
|
# Sends a DELETE request.
|
@@ -94,7 +94,7 @@ class PopIt
|
|
94
94
|
# @param [Hash] opts key-value pairs for the query string
|
95
95
|
# @return [Hash] an empty hash
|
96
96
|
def delete(path, opts = {})
|
97
|
-
request
|
97
|
+
request(:delete, path, opts)
|
98
98
|
end
|
99
99
|
|
100
100
|
private
|
@@ -104,18 +104,22 @@ private
|
|
104
104
|
|
105
105
|
response = case http_method
|
106
106
|
when :get
|
107
|
-
self.class.send
|
107
|
+
self.class.send(http_method, path, :query => opts)
|
108
108
|
when :delete
|
109
|
-
self.class.send
|
109
|
+
self.class.send(http_method, path, :basic_auth => {:username => username, :password => password}, :query => opts)
|
110
110
|
when :post, :put
|
111
|
-
self.class.send
|
111
|
+
self.class.send(http_method, path, :basic_auth => {:username => username, :password => password}, :body => JSON.dump(opts), :headers => {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
112
112
|
end
|
113
113
|
|
114
114
|
unless ['200', '201', '204'].include?(response.response.code)
|
115
|
-
if response.response.content_type == 'text/html'
|
116
|
-
|
115
|
+
message = if response.response.content_type == 'text/html'
|
116
|
+
"HTTP #{response.response.code}"
|
117
|
+
elsif response.parsed_response['error']
|
118
|
+
response.parsed_response['error']
|
119
|
+
elsif response.parsed_response['errors']
|
120
|
+
response.parsed_response['errors'].join(', ')
|
117
121
|
else
|
118
|
-
|
122
|
+
response.parsed_response
|
119
123
|
end
|
120
124
|
case response.response.code
|
121
125
|
when '404'
|
@@ -143,19 +147,19 @@ private
|
|
143
147
|
end
|
144
148
|
|
145
149
|
def get(opts = {})
|
146
|
-
@klass.get
|
150
|
+
@klass.get(chain.join('/'), opts)
|
147
151
|
end
|
148
152
|
|
149
153
|
def post(opts = {})
|
150
|
-
@klass.post
|
154
|
+
@klass.post(chain.join('/'), opts)
|
151
155
|
end
|
152
156
|
|
153
157
|
def put(opts = {})
|
154
|
-
@klass.put
|
158
|
+
@klass.put(chain.join('/'), opts)
|
155
159
|
end
|
156
160
|
|
157
161
|
def delete(opts = {})
|
158
|
-
@klass.delete
|
162
|
+
@klass.delete(chain.join('/'), opts)
|
159
163
|
end
|
160
164
|
|
161
165
|
def method_missing(*args)
|
data/lib/popit/version.rb
CHANGED
data/spec/popit_spec.rb
CHANGED
@@ -82,8 +82,9 @@ describe PopIt do
|
|
82
82
|
|
83
83
|
context 'when authenticated' do
|
84
84
|
it 'should create, update and delete an item' do
|
85
|
-
response = authenticated.persons.post :name => 'John Smith', :slug => 'john-smith'
|
85
|
+
response = authenticated.persons.post :name => 'John Smith', :slug => 'john-smith', :contact_details => [{:type => 'email', :value => 'test@example.com'}]
|
86
86
|
id = response['id']
|
87
|
+
contact_detail_id = response['contact_details'][0]['id']
|
87
88
|
response['name'].should == 'John Smith'
|
88
89
|
|
89
90
|
response = authenticated.persons(id).put :id => id, :name => 'John Doe', :slug => 'john-doe'
|
@@ -93,11 +94,15 @@ describe PopIt do
|
|
93
94
|
'slug' => 'john-doe',
|
94
95
|
'memberships' => [],
|
95
96
|
'links' => [],
|
96
|
-
'contact_details' => [
|
97
|
+
'contact_details' => [{
|
98
|
+
'id' => contact_detail_id,
|
99
|
+
'type' => 'email',
|
100
|
+
'value' => 'test@example.com',
|
101
|
+
}],
|
97
102
|
'identifiers' => [],
|
98
103
|
'other_names' => [],
|
99
104
|
'url' => 'http://tttest.popit.mysociety.org/api/v0.1/persons/' + id,
|
100
|
-
'html_url' => 'http://tttest.popit.mysociety.org/persons/
|
105
|
+
'html_url' => 'http://tttest.popit.mysociety.org/persons/' + id,
|
101
106
|
}
|
102
107
|
authenticated.persons(id).get['name'].should == 'John Doe'
|
103
108
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: popit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Open North
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|