statraptor 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +14 -0
- data/README.md +1 -0
- data/lib/statraptor/client/users.rb +12 -0
- data/lib/statraptor/version.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/statrapator/client/user_spec.rb +49 -3
- data/statraptor.gemspec +1 -1
- metadata +5 -5
data/CHANGELOG.md
CHANGED
@@ -14,3 +14,17 @@
|
|
14
14
|
* All other errors are raised as a generic StatRaptor::Error
|
15
15
|
* Errors now include a nice parsed error message if one exists in the StatRaptor response
|
16
16
|
* All public methods now return a hash on success instead of JSON
|
17
|
+
|
18
|
+
## 0.2.1 (February 29, 2012)
|
19
|
+
|
20
|
+
* Use RestClient as the default HTTP library
|
21
|
+
* Typhoeus bug forced this change: https://github.com/dbalatero/typhoeus/issues/96
|
22
|
+
* Set a User-Agent header for all HTTP requests
|
23
|
+
|
24
|
+
## 0.2.2 (February 29, 2012)
|
25
|
+
|
26
|
+
* Small change to depend on an earlier release of RestClient to improve gem compatibility
|
27
|
+
|
28
|
+
## 0.2.3 (March 1, 2012)
|
29
|
+
|
30
|
+
* Add suppoort for `client.find_or_create_user`
|
data/README.md
CHANGED
@@ -16,6 +16,7 @@ client = StatRaptor::Client.new
|
|
16
16
|
|
17
17
|
# Manage users
|
18
18
|
client.create_user(:email => "timmy@example.com", :chargify_api_key => "XYZ456")
|
19
|
+
client.find_or_create_user(:email => "timmy@example.com", :chargify_api_key => "XYZ456")
|
19
20
|
client.delete_user("akskd8328389281728918")
|
20
21
|
client.get_users
|
21
22
|
|
@@ -12,6 +12,18 @@ module StatRaptor
|
|
12
12
|
def get_users
|
13
13
|
get("/api/v1/users.json")
|
14
14
|
end
|
15
|
+
|
16
|
+
def find_or_create_user(params = {})
|
17
|
+
users = get_users
|
18
|
+
user = users.detect{|u| (u['email'] == params[:email]) && (u['chargify_api_key'] == params[:chargify_api_key])}
|
19
|
+
!!user ? user : create_user(params)
|
20
|
+
end
|
21
|
+
|
22
|
+
# This StatRaptor API endpoint isn't available yet
|
23
|
+
def get_user(user_credentials)
|
24
|
+
raise NotImplementedError
|
25
|
+
get("/api/v1/users/#{user_credentials}.json")
|
26
|
+
end
|
15
27
|
end
|
16
28
|
end
|
17
29
|
end
|
data/lib/statraptor/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -16,6 +16,7 @@ RSpec.configure do |config|
|
|
16
16
|
config.filter_run :focused => true
|
17
17
|
config.run_all_when_everything_filtered = true
|
18
18
|
config.alias_example_to :fit, :focused => true
|
19
|
+
config.alias_example_to :xit, :disabled => true
|
19
20
|
config.color_enabled = true
|
20
21
|
|
21
22
|
# so we can use `:vcr` rathaner than `:vcr => true`;
|
@@ -36,6 +37,7 @@ VCR.configure do |config|
|
|
36
37
|
config.cassette_library_dir = 'spec/cassettes'
|
37
38
|
config.configure_rspec_metadata!
|
38
39
|
config.default_cassette_options = {:record => :new_episodes, :match_requests_on => [:uri, :body, :headers]}
|
40
|
+
config.allow_http_connections_when_no_cassette = true
|
39
41
|
end
|
40
42
|
|
41
43
|
def platform_credentials
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe StatRaptor::Client::Users do
|
4
4
|
let(:client) { StatRaptor::Client.new }
|
5
5
|
|
6
|
-
|
6
|
+
describe "#create_user", :vcr do
|
7
7
|
it "returns a user hash on success" do
|
8
8
|
email = random_email
|
9
9
|
user = client.create_user(:email => email, :chargify_api_key => "ABC123")
|
@@ -13,7 +13,7 @@ describe StatRaptor::Client::Users do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
describe "#delete_user", :vcr do
|
17
17
|
it "returns the user hash on success" do
|
18
18
|
email = random_email
|
19
19
|
user = client.create_user(:email => email, :chargify_api_key => "XYZ123")
|
@@ -24,7 +24,7 @@ describe StatRaptor::Client::Users do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
describe "#get_users", :vcr do
|
28
28
|
it "returns an array of hashes" do
|
29
29
|
users = client.get_users
|
30
30
|
users.count.should > 1
|
@@ -32,4 +32,50 @@ describe StatRaptor::Client::Users do
|
|
32
32
|
users.first.should be_a(Hash)
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
describe "#find_or_create_user" do
|
37
|
+
it "returns the user hash if the user already exists" do
|
38
|
+
email = random_email
|
39
|
+
user = client.create_user(:email => email, :chargify_api_key => "ABCDEF")
|
40
|
+
|
41
|
+
lambda {
|
42
|
+
@user = client.find_or_create_user(:email => email, :chargify_api_key => "ABCDEF")
|
43
|
+
}.should_not raise_error(StatRaptor::Error)
|
44
|
+
|
45
|
+
@user['user_credentials'].should == user['user_credentials']
|
46
|
+
@user['chargify_api_key'].should == user['chargify_api_key']
|
47
|
+
@user['email'].should == user['email']
|
48
|
+
end
|
49
|
+
|
50
|
+
it "creates a new user if the user does not exist" do
|
51
|
+
email = random_email
|
52
|
+
user = client.find_or_create_user(:email => email, :chargify_api_key => "123456")
|
53
|
+
user["user_credentials"].should_not be_nil
|
54
|
+
user['chargify_api_key'].should == "123456"
|
55
|
+
user['email'].should == email
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#get_user", :vcr do
|
60
|
+
it "raises a NotImplementedError" do
|
61
|
+
lambda {
|
62
|
+
client.get_user('leroy-jenkins')
|
63
|
+
}.should raise_error(NotImplementedError)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "raises a StatRaptor::Error::NotFound if the user doesn't exist", :pending => true do
|
67
|
+
lambda {
|
68
|
+
client.get_user("silly-fake-user")
|
69
|
+
}.should raise_error(StatRaptor::Error::NotFound)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns a user hash if the user is found", :pending => true do
|
73
|
+
email = random_email
|
74
|
+
existing_user = client.create_user(:email => email, :chargify_api_key => "foobar-123")
|
75
|
+
user = client.get_user(existing_user["user_credentials"])
|
76
|
+
user['user_credentials'].should == existing_user["user_credentials"]
|
77
|
+
user['chargify_api_key'].should == 'foobar-123'
|
78
|
+
user['email'].should == email
|
79
|
+
end
|
80
|
+
end
|
35
81
|
end
|
data/statraptor.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.name = "statraptor"
|
9
9
|
s.version = StatRaptor::VERSION
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
|
-
s.date = "2012-
|
11
|
+
s.date = "2012-03-01"
|
12
12
|
s.authors = ["Shay Frendt"]
|
13
13
|
s.email = "shay.frendt@gmail.com"
|
14
14
|
s.homepage = "http://github.com/chargify/statraptor"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statraptor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Shay Frendt
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-03-01 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
requirements:
|
123
123
|
- - "="
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
hash:
|
125
|
+
hash: 3403259733
|
126
126
|
segments:
|
127
127
|
- 2
|
128
128
|
- 0
|