popit 0.0.7 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e107fa8a67b9fb91253acc05db2c906befc9463
4
- data.tar.gz: 5acea070cae8ef2839b9463406d0a8e00de81938
3
+ metadata.gz: 3bf9709f2c6a428a607fe1ad33b6c9b075047ed2
4
+ data.tar.gz: cd7f8c448ace3f050a8ba0c1b5a588d5b73ed0c7
5
5
  SHA512:
6
- metadata.gz: 41a16756393b990c236499ca3ca00ca63ed2cfc1c564543212c1206b17e24d1432af99cc382e6383c2ab34128beceeb825b3dfafc71c4c0f6ed541f2ca77bd66
7
- data.tar.gz: 6a5a620436db1c783ca726cb94d68968c80de9fdd9d523317b91398eeb9908936cc51cc5058338e2c9b08bdf579bb224a4dcef030ad3bb288fe0746ddacb23bc
6
+ metadata.gz: 024bb1ec703c7c84ba724806e3ba86a40954c16d3ef7ff3380787a9dcd02cdc724ffd7e4fa1d38441d941f91a4379cb9da7c1262aa490d64488e2526dd986f26
7
+ data.tar.gz: 5894ea311751bec451f96a10d386f9069fa20657ac8685a76dd104f40dc0725dc82549c1576221ae9a87e0ed78d6c78815f1c365ff7a83cbe8ce2a7509aeedc5
data/.travis.yml CHANGED
@@ -1,14 +1,9 @@
1
- ---
2
1
  language: ruby
3
2
  rvm:
4
3
  - 1.9.2
5
4
  - 1.9.3
6
5
  - 2.0.0
6
+ - 2.1.0
7
7
  env:
8
8
  global:
9
- - TRAVIS_SECURE_ENV_VARS: true
10
- - secure: ! 'Q1wjuxr364WRXFTDD8jdunJG59Xl2iYFtehm+5d6UAR9mY9Ohv4TLqT6QhHu
11
-
12
- 1mdR575m90w3y1ZuS3NnzoUiMcrL+Osoza/tzBOch0+doXMqCXyZcgnSlNgV
13
-
14
- 16TcY+GFYbBnGnlq+5UoBCjOb3eqHdWqoASdT4DPIijGmvEzBDs='
9
+ secure: OYhs6gJoC2eZr4H3uH9X1R36rxIj6ISiK8QO+tdhSxRyUZsKA94iYEqUsvb9jtyE+5NYlsWx/0SQdUQsRS06CIdph1tHKXxzAz8e8/nZaUoQMlg2z7ba09ah57Catlt6ouRaxa++BXbwKfRsmG8aYhSDy8bUEwa9VSi1glE65aY=
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  A Ruby wrapper for the [PopIt](http://popit.mysociety.org/) API, which allows you to create, read, update and delete documents from PopIt.
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/popit.svg)](http://badge.fury.io/rb/popit)
5
6
  [![Build Status](https://secure.travis-ci.org/opennorth/popit-ruby.png)](http://travis-ci.org/opennorth/popit-ruby)
6
7
  [![Dependency Status](https://gemnasium.com/opennorth/popit-ruby.png)](https://gemnasium.com/opennorth/popit-ruby)
7
8
  [![Coverage Status](https://coveralls.io/repos/opennorth/popit-ruby/badge.png?branch=master)](https://coveralls.io/r/opennorth/popit-ruby)
@@ -31,8 +32,8 @@ You can pass these options to `PopIt.new`:
31
32
  * `:host_name` the PopIt API's host name – defaults to "popit.mysociety.org"
32
33
  * `:port` the PopIt API's port – defaults to 80
33
34
  * `:version` the PopIt API version – defaults to "v0.1"
34
- * `:user` a user name – if blank, the API will be read-only
35
- * `:password` the user's password
35
+ * `:apikey` an API key – if blank, the API will be read-only
36
+ * `:max_retries` the number of times to retry the API in case of errors - defaults to 0
36
37
 
37
38
  For brevity, we only show examples below for `persons` documents, but you can use the same code to operate on organizations and memberships by substituting `organizations` or `memberships` for `persons`.
38
39
 
@@ -108,8 +109,7 @@ api.persons.get('foo') # raises PopIt::PageNotFound with "page not found"
108
109
  To run the tests:
109
110
 
110
111
  export INSTANCE_NAME=YOUR_POPIT_INSTANCE_NAME
111
- export POPIT_USER=YOUR_POPIT_EMAIL_ADDRESS
112
- export POPIT_PASSWORD=YOUR_POPIT_PASSWORD
112
+ export POPIT_API_KEY=YOUR_POPIT_API_KEY
113
113
  bundle exec rake
114
114
 
115
115
  **If you care about the data in an instance, do not use that instance to run tests!**
data/lib/popit.rb CHANGED
@@ -35,10 +35,8 @@ class PopIt
35
35
  attr_reader :port
36
36
  # The PopIt API version, eg "v0.1"
37
37
  attr_reader :version
38
- # A user name.
39
- attr_reader :username
40
- # The user's password.
41
- attr_reader :password
38
+ # An API key.
39
+ attr_reader :apikey
42
40
  # The maximum number of retries in case of HTTP 503 Service Unavailable errors.
43
41
  attr_reader :max_retries
44
42
 
@@ -49,8 +47,7 @@ class PopIt
49
47
  # @option opts [String] :host_name the PopIt API's host name, eg "popit.mysociety.org"
50
48
  # @option opts [String] :post the PopIt API's port, eg 80
51
49
  # @option opts [String] :version the PopIt API version, eg "v1"
52
- # @option opts [String] :user a user name
53
- # @option opts [String] :password the user's password
50
+ # @option opts [String] :apikey an API key
54
51
  # @option opts [String] :max_retries the maximum number of retries in case of
55
52
  # HTTP 503 Service Unavailable errors
56
53
  def initialize(opts = {})
@@ -62,8 +59,7 @@ class PopIt
62
59
  @host_name = opts[:host_name] || 'popit.mysociety.org'
63
60
  @port = opts[:port] || 80
64
61
  @version = opts[:version] || 'v0.1'
65
- @username = opts[:user]
66
- @password = opts[:password]
62
+ @apikey = opts[:apikey]
67
63
  @max_retries = opts[:max_retries] || 0
68
64
 
69
65
  end
@@ -115,9 +111,9 @@ private
115
111
  when :get
116
112
  self.class.send(http_method, path, :query => opts)
117
113
  when :delete
118
- self.class.send(http_method, path, :basic_auth => {:username => username, :password => password}, :query => opts)
114
+ self.class.send(http_method, path, :query => opts.merge(:apikey => apikey))
119
115
  when :post, :put
120
- self.class.send(http_method, path, :basic_auth => {:username => username, :password => password}, :body => JSON.dump(opts), :headers => {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
116
+ self.class.send(http_method, path, :body => JSON.dump(opts.merge(:apikey => apikey)), :headers => {'Content-Type' => 'application/json'})
121
117
  end
122
118
 
123
119
  unless ['200', '201', '204'].include?(response.response.code)
data/lib/popit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class PopIt
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/popit.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  s.add_runtime_dependency('httparty', '~> 0.10.0')
21
- s.add_development_dependency('rspec', '~> 2.10')
21
+ s.add_development_dependency('rspec', '~> 3.1.0')
22
22
  s.add_development_dependency('rake')
23
23
  s.add_development_dependency('coveralls')
24
24
  end
data/spec/popit_spec.rb CHANGED
@@ -13,8 +13,7 @@ describe PopIt do
13
13
  let :authenticated do
14
14
  PopIt.new({
15
15
  :instance_name => ENV['INSTANCE_NAME'] || 'tttest',
16
- :user => ENV['POPIT_USER'] || 'james@opennorth.ca',
17
- :password => ENV['POPIT_PASSWORD'],
16
+ :apikey => ENV['POPIT_API_KEY'],
18
17
  })
19
18
  end
20
19
 
@@ -48,12 +47,12 @@ describe PopIt do
48
47
  context 'when unauthenticated' do
49
48
  it 'should get all items' do
50
49
  response = unauthenticated.persons.get
51
- response.should be_an(Array)
50
+ expect(response).to be_an(Array)
52
51
  end
53
52
 
54
53
  it 'should get one item by name' do
55
54
  response = unauthenticated.persons.get(:name => 'Foo')
56
- response.should be_an(Array)
55
+ expect(response).to be_an(Array)
57
56
  end
58
57
 
59
58
  it 'should get one item' do
@@ -62,7 +61,7 @@ describe PopIt do
62
61
  # other_names, personal_details and adds positions_api_url to meta.
63
62
  person.each do |k,v|
64
63
  unless k == 'meta'
65
- response[k].should == v
64
+ expect(response[k]).to eq(v)
66
65
  end
67
66
  end
68
67
  end
@@ -72,15 +71,15 @@ describe PopIt do
72
71
  end
73
72
 
74
73
  it 'should fail to create an item' do
75
- expect {unauthenticated.persons.post(:name => 'John Doe', :slug => 'john-doe')}.to raise_error(PopIt::NotAuthenticated, 'not authenticated')
74
+ expect {unauthenticated.persons.post(:name => 'John Doe', :slug => 'john-doe')}.to raise_error(PopIt::NotAuthenticated, 'Unauthorized')
76
75
  end
77
76
 
78
77
  it 'should fail to update an item' do
79
- expect {unauthenticated.persons(id).put(:id => id, :name => 'John Doe', :slug => 'john-doe')}.to raise_error(PopIt::NotAuthenticated, 'not authenticated')
78
+ expect {unauthenticated.persons(id).put(:id => id, :name => 'John Doe', :slug => 'john-doe')}.to raise_error(PopIt::NotAuthenticated, 'Unauthorized')
80
79
  end
81
80
 
82
81
  it 'should fail to delete an item' do
83
- expect {unauthenticated.persons(id).delete}.to raise_error(PopIt::NotAuthenticated, 'not authenticated')
82
+ expect {unauthenticated.persons(id).delete}.to raise_error(PopIt::NotAuthenticated, 'Unauthorized')
84
83
  end
85
84
  end
86
85
 
@@ -89,10 +88,10 @@ describe PopIt do
89
88
  response = authenticated.persons.post(:name => 'John Smith', :slug => 'john-smith', :contact_details => [{:type => 'email', :value => 'test@example.com'}])
90
89
  id = response['id']
91
90
  contact_detail_id = response['contact_details'][0]['id']
92
- response['name'].should == 'John Smith'
91
+ expect(response['name']).to eq('John Smith')
93
92
 
94
93
  response = authenticated.persons(id).put(:id => id, :name => 'John Doe', :slug => 'john-doe')
95
- response.should == {
94
+ expect(response).to eq({
96
95
  'id' => id,
97
96
  'name' => 'John Doe',
98
97
  'slug' => 'john-doe',
@@ -107,20 +106,20 @@ describe PopIt do
107
106
  'other_names' => [],
108
107
  'url' => 'http://tttest.popit.mysociety.org/api/v0.1/persons/' + id,
109
108
  'html_url' => 'http://tttest.popit.mysociety.org/persons/' + id,
110
- }
111
- authenticated.persons(id).get['name'].should == 'John Doe'
109
+ })
110
+ expect(authenticated.persons(id).get['name']).to eq('John Doe')
112
111
 
113
112
  response = authenticated.persons(id).delete
114
- response.should == nil
113
+ expect(response).to be_nil
115
114
  expect {authenticated.persons(id).get}.to raise_error(PopIt::PageNotFound, "id '#{id}' not found")
116
115
  end
117
116
  end
118
117
 
119
118
  context 'when service unavailable' do
120
119
  before :each do
121
- PopIt.stub(:get) do
120
+ allow(PopIt).to receive(:get) do
122
121
  response = Net::HTTPServiceUnavailable.new('1.1', 503, 'Service Unavailable')
123
- response.stub(:body => '', :code => '503')
122
+ allow(response).to receive_messages(:body => '', :code => '503')
124
123
  HTTParty::Response.new(HTTParty::Request.new(Net::HTTP::Get, '/'), response, lambda {})
125
124
  end
126
125
  end
@@ -128,13 +127,13 @@ describe PopIt do
128
127
  it 'should fail immediately' do
129
128
  time = Time.now
130
129
  expect {unauthenticated.persons.get}.to raise_error(PopIt::ServiceUnavailable)
131
- Time.now.should be_within(1).of(time)
130
+ expect(Time.now).to be_within(1).of(time)
132
131
  end
133
132
 
134
133
  it 'should backoff exponentially' do
135
134
  time = Time.now
136
135
  expect {exponential_backoff.persons.get}.to raise_error(PopIt::ServiceUnavailable)
137
- Time.now.should_not be_within(5).of(time)
136
+ expect(Time.now).to_not be_within(5).of(time)
138
137
  end
139
138
  end
140
139
  end
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.7
4
+ version: 0.0.8
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-05-09 00:00:00.000000000 Z
11
+ date: 2014-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.10'
33
+ version: 3.1.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.10'
40
+ version: 3.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -113,3 +113,4 @@ summary: The PopIt API Ruby Gem
113
113
  test_files:
114
114
  - spec/popit_spec.rb
115
115
  - spec/spec_helper.rb
116
+ has_rdoc: