statraptor 0.1.0 → 0.2.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/CHANGELOG.md +14 -3
- data/README.md +1 -0
- data/lib/statraptor/client/graphs.rb +6 -7
- data/lib/statraptor/client/projects.rb +4 -6
- data/lib/statraptor/client/users.rb +7 -7
- data/lib/statraptor/client.rb +55 -3
- data/lib/statraptor/config.rb +13 -7
- data/lib/statraptor/error/unauthorized.rb +5 -0
- data/lib/statraptor/version.rb +1 -1
- data/spec/spec_helper.rb +7 -1
- data/spec/statrapator/client/graphs_spec.rb +16 -0
- data/spec/statrapator/client/projects_spec.rb +42 -0
- data/spec/statrapator/client/user_spec.rb +33 -0
- data/spec/{client_spec.rb → statrapator/client_spec.rb} +2 -1
- data/spec/{config_spec.rb → statrapator/config_spec.rb} +21 -1
- data/spec/statrapator/error_spec.rb +13 -0
- data/statraptor.gemspec +1 -1
- data/todo.taskpaper +3 -0
- metadata +19 -15
- data/spec/client/graphs_spec.rb +0 -41
- data/spec/client/projects_spec.rb +0 -42
- data/spec/client/user_spec.rb +0 -31
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
-
## 0.1.0 (February
|
1
|
+
## 0.1.0 (February 24, 2012)
|
2
2
|
|
3
|
-
|
3
|
+
* Added support for User, Project, and Graph resources
|
4
4
|
|
5
|
-
|
5
|
+
|
6
|
+
## 0.2.0 (February 28, 2012)
|
7
|
+
|
8
|
+
* Added support for listing users with `client.get_users`
|
9
|
+
* Added StatRaptor.disable\_ssl\_peer\_verification config option
|
10
|
+
* Implemented StatRaptor.timeout config option
|
11
|
+
* Improve how errors are raised
|
12
|
+
* A 404 is now properly raised as a StatRaptor::Error::NotFound
|
13
|
+
* A 401 is now properly raised as a StatRaptor::Error::Unauthorized
|
14
|
+
* All other errors are raised as a generic StatRaptor::Error
|
15
|
+
* Errors now include a nice parsed error message if one exists in the StatRaptor response
|
16
|
+
* All public methods now return a hash on success instead of JSON
|
data/README.md
CHANGED
@@ -17,6 +17,7 @@ client = StatRaptor::Client.new
|
|
17
17
|
# Manage users
|
18
18
|
client.create_user(:email => "timmy@example.com", :chargify_api_key => "XYZ456")
|
19
19
|
client.delete_user("akskd8328389281728918")
|
20
|
+
client.get_users
|
20
21
|
|
21
22
|
# Manage projects
|
22
23
|
client.create_project(:user_credentials => "3892839akslje",
|
@@ -1,27 +1,26 @@
|
|
1
1
|
module StatRaptor
|
2
2
|
class Client
|
3
3
|
module Graphs
|
4
|
-
def get_revenue_graph_data(params={})
|
4
|
+
def get_revenue_graph_data(params = {})
|
5
5
|
graph_data("revenue", params)
|
6
6
|
end
|
7
7
|
|
8
|
-
def get_subscribers_graph_data(params={})
|
8
|
+
def get_subscribers_graph_data(params = {})
|
9
9
|
graph_data("subscribers", params)
|
10
10
|
end
|
11
11
|
|
12
|
-
def get_average_lifetime_value_graph_data(params={})
|
12
|
+
def get_average_lifetime_value_graph_data(params = {})
|
13
13
|
graph_data("average_lifetime_value", params)
|
14
14
|
end
|
15
15
|
|
16
|
-
def get_churn_graph_data(params={})
|
16
|
+
def get_churn_graph_data(params = {})
|
17
17
|
graph_data("churn", params)
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
-
def graph_data(type, params={})
|
23
|
-
|
24
|
-
response.body
|
22
|
+
def graph_data(type, params = {})
|
23
|
+
get("/graphs/#{type}.json", params)
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
module StatRaptor
|
2
2
|
class Client
|
3
3
|
module Projects
|
4
|
-
def create_project(params={})
|
5
|
-
|
6
|
-
response.body
|
4
|
+
def create_project(params = {})
|
5
|
+
post("/projects", params)
|
7
6
|
end
|
8
7
|
|
9
|
-
def delete_project(params={})
|
10
|
-
|
11
|
-
handle_response(response)
|
8
|
+
def delete_project(params = {})
|
9
|
+
delete("/projects/#{params[:subdomain]}", :user_credentials => params[:user_credentials])
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'statraptor/error/not_found'
|
2
|
-
|
3
1
|
module StatRaptor
|
4
2
|
class Client
|
5
3
|
module Users
|
6
|
-
def create_user(params={})
|
7
|
-
|
8
|
-
response.body
|
4
|
+
def create_user(params = {})
|
5
|
+
post("/users.json", :user => params)
|
9
6
|
end
|
10
7
|
|
11
8
|
def delete_user(user_credentials)
|
12
|
-
|
13
|
-
|
9
|
+
delete("/users/#{user_credentials}.json")
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_users
|
13
|
+
get("/users.json")
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/statraptor/client.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'statraptor/config'
|
2
2
|
require 'statraptor/error'
|
3
|
+
require 'statraptor/error/not_found'
|
4
|
+
require 'statraptor/error/unauthorized'
|
3
5
|
|
4
6
|
module StatRaptor
|
5
7
|
class Client
|
@@ -26,15 +28,65 @@ module StatRaptor
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
31
|
+
private
|
32
|
+
|
33
|
+
def get(url, params = {})
|
34
|
+
request_and_parse :get, url, params
|
35
|
+
end
|
36
|
+
|
37
|
+
def post(url, params = {})
|
38
|
+
request_and_parse :post, url, params
|
39
|
+
end
|
40
|
+
|
41
|
+
def put(url, params = {})
|
42
|
+
request_and_parse :put, url, params
|
43
|
+
end
|
44
|
+
|
45
|
+
def delete(url, params = {})
|
46
|
+
request_and_parse :delete, url, params
|
47
|
+
end
|
48
|
+
|
49
|
+
def request_and_parse(method, url, params = {})
|
50
|
+
response = request_api_response(method, url, params)
|
51
|
+
handle_response(response)
|
52
|
+
parse_response(response)
|
53
|
+
end
|
54
|
+
|
55
|
+
def request_api_response(method, url, params = {})
|
56
|
+
params.merge!(:platform_credentials => StatRaptor.platform_credentials)
|
57
|
+
|
58
|
+
Typhoeus::Request.run(
|
59
|
+
"#{StatRaptor.endpoint}/api/v1#{url}",
|
60
|
+
:method => method,
|
61
|
+
:params => params,
|
62
|
+
:disable_ssl_peer_verification => StatRaptor.disable_ssl_peer_verification,
|
63
|
+
:timeout => StatRaptor.timeout
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
def parse_response(response)
|
68
|
+
JSON.parse(response.body)
|
69
|
+
rescue JSON::ParserError
|
70
|
+
{}
|
71
|
+
end
|
72
|
+
|
29
73
|
def handle_response(response)
|
30
74
|
case response.code
|
31
75
|
when 200
|
32
76
|
return true
|
33
|
-
when
|
34
|
-
|
35
|
-
|
77
|
+
when 404
|
78
|
+
raise StatRaptor::Error::NotFound.new(format_error(response))
|
79
|
+
when 401
|
80
|
+
raise StatRaptor::Error::Unauthorized.new(format_error(response))
|
81
|
+
else
|
82
|
+
raise StatRaptor::Error.new(format_error(response))
|
36
83
|
end
|
37
84
|
end
|
38
85
|
|
86
|
+
def format_error(response)
|
87
|
+
parsed_response = parse_response(response)
|
88
|
+
parsed_response["errors"] ? parsed_response["errors"].join(", ") : ''
|
89
|
+
end
|
90
|
+
|
39
91
|
end
|
40
92
|
end
|
data/lib/statraptor/config.rb
CHANGED
@@ -11,18 +11,23 @@ module StatRaptor
|
|
11
11
|
# The value sent in the 'User-Agent' header if none is set
|
12
12
|
DEFAULT_USER_AGENT = "StatRaptor Ruby Gem #{StatRaptor::VERSION}"
|
13
13
|
|
14
|
-
# The timeout in
|
15
|
-
DEFAULT_TIMEOUT =
|
14
|
+
# The timeout (in milliseconds) that will be used if none is set
|
15
|
+
DEFAULT_TIMEOUT = 5000 # 5 seconds
|
16
16
|
|
17
17
|
# The default platform_credentials if none are set
|
18
18
|
DEFAULT_PLATFORM_CREDENTIALS = nil
|
19
19
|
|
20
|
+
# If you’re hitting a non-verifiable SSL server
|
21
|
+
# then you’ll have to disable peer verification to make SSL work
|
22
|
+
DEFAULT_DISABLE_SSL_PEER_VERIFICATION = false
|
23
|
+
|
20
24
|
# An array of valid keys in the options hash when configuring a {StatRaptor::Client}
|
21
25
|
VALID_OPTIONS_KEYS = [
|
22
26
|
:endpoint,
|
23
27
|
:user_agent,
|
24
28
|
:timeout,
|
25
|
-
:platform_credentials
|
29
|
+
:platform_credentials,
|
30
|
+
:disable_ssl_peer_verification
|
26
31
|
]
|
27
32
|
|
28
33
|
attr_accessor *VALID_OPTIONS_KEYS
|
@@ -47,10 +52,11 @@ module StatRaptor
|
|
47
52
|
|
48
53
|
# Reset all configuration options to defaults
|
49
54
|
def reset
|
50
|
-
self.endpoint
|
51
|
-
self.user_agent
|
52
|
-
self.timeout
|
53
|
-
self.platform_credentials
|
55
|
+
self.endpoint = DEFAULT_ENDPOINT
|
56
|
+
self.user_agent = DEFAULT_USER_AGENT
|
57
|
+
self.timeout = DEFAULT_TIMEOUT
|
58
|
+
self.platform_credentials = DEFAULT_PLATFORM_CREDENTIALS
|
59
|
+
self.disable_ssl_peer_verification = DEFAULT_DISABLE_SSL_PEER_VERIFICATION
|
54
60
|
self
|
55
61
|
end
|
56
62
|
end
|
data/lib/statraptor/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -24,6 +24,8 @@ RSpec.configure do |config|
|
|
24
24
|
config.before(:all) do
|
25
25
|
StatRaptor.configure do |config|
|
26
26
|
config.platform_credentials = platform_credentials
|
27
|
+
config.endpoint = statraptor_endpoint
|
28
|
+
config.disable_ssl_peer_verification = true
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -32,7 +34,7 @@ VCR.configure do |config|
|
|
32
34
|
config.hook_into :webmock
|
33
35
|
config.cassette_library_dir = 'spec/cassettes'
|
34
36
|
config.configure_rspec_metadata!
|
35
|
-
config.default_cassette_options = {:record => :
|
37
|
+
config.default_cassette_options = {:record => :once, :match_requests_on => [:uri, :body, :headers]}
|
36
38
|
end
|
37
39
|
|
38
40
|
def platform_credentials
|
@@ -51,6 +53,10 @@ def user_credentials
|
|
51
53
|
remote_configuration["user_credentials"]
|
52
54
|
end
|
53
55
|
|
56
|
+
def statraptor_endpoint
|
57
|
+
remote_configuration["endpoint"]
|
58
|
+
end
|
59
|
+
|
54
60
|
private
|
55
61
|
|
56
62
|
def remote_configuration
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StatRaptor::Client::Graphs, :vcr do
|
4
|
+
let(:client) { StatRaptor::Client.new }
|
5
|
+
|
6
|
+
["revenue", "subscribers", "average_lifetime_value", "churn"].each do |graph_name|
|
7
|
+
context "#get_#{graph_name}_graph_data" do
|
8
|
+
it "should return a hash of #{graph_name} graph data" do
|
9
|
+
graph = client.send("get_#{graph_name}_graph_data", :user_credentials => user_credentials, :subdomain => chargify_subdomain)
|
10
|
+
graph.should be_a(Hash)
|
11
|
+
graph["graph_data"].keys.should include("actual", "projected", "x_labels")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StatRaptor::Client::Projects do
|
4
|
+
let(:client) { StatRaptor::Client.new }
|
5
|
+
|
6
|
+
context "#create_project", :vcr do
|
7
|
+
before do
|
8
|
+
@user = client.create_user(:email => "tommy@example.com", :chargify_api_key => "ABC123")
|
9
|
+
@user["user_credentials"].should_not be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns a project hash on success" do
|
13
|
+
project = client.create_project(:user_credentials => @user["user_credentials"], :project => {
|
14
|
+
:name => "Zippy Sunday", :subdomain => "zippy-sunday", :component => "basic"
|
15
|
+
})
|
16
|
+
|
17
|
+
project["name"].should == "Zippy Sunday"
|
18
|
+
project["subdomain"].should == "zippy-sunday"
|
19
|
+
project["component"].should == "basic"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "#delete_project", :vcr do
|
24
|
+
it "returns the project hash on success" do
|
25
|
+
user = client.create_user(:email => "sammy@example.com", :chargify_api_key => "ABC123")
|
26
|
+
project = client.create_project(:user_credentials => user["user_credentials"], :project => {
|
27
|
+
:name => "Modern Marvels", :subdomain => "modern-marvels", :component => "advanced"
|
28
|
+
})
|
29
|
+
|
30
|
+
deleted_project = client.delete_project(:user_credentials => user["user_credentials"], :subdomain => "modern-marvels")
|
31
|
+
deleted_project["name"].should == "Modern Marvels"
|
32
|
+
deleted_project["subdomain"].should == "modern-marvels"
|
33
|
+
deleted_project["component"].should == "advanced"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises an unauthorized exception if the user credentials are incorrect" do
|
37
|
+
lambda {
|
38
|
+
client.delete_project(:user_credentials => "abc123", :subdomain => "modern-marvels")
|
39
|
+
}.should raise_error(StatRaptor::Error::Unauthorized, "Invalid user API key specified")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StatRaptor::Client::Users do
|
4
|
+
let(:client) { StatRaptor::Client.new }
|
5
|
+
|
6
|
+
context "#create", :vcr do
|
7
|
+
it "returns a user hash on success" do
|
8
|
+
user = client.create_user(:email => "austin@example.com", :chargify_api_key => "ABC123")
|
9
|
+
user["user_credentials"].should_not be_nil
|
10
|
+
user["chargify_api_key"].should == "ABC123"
|
11
|
+
user["email"].should == "austin@example.com"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "#delete_user", :vcr do
|
16
|
+
it "returns the user hash on success" do
|
17
|
+
user = client.create_user(:email => "leroy@example.com", :chargify_api_key => "XYZ123")
|
18
|
+
deleted_user = client.delete_user(user["user_credentials"])
|
19
|
+
deleted_user["user_credentials"].should == user["user_credentials"]
|
20
|
+
deleted_user["chargify_api_key"].should == "XYZ123"
|
21
|
+
deleted_user["email"].should == "leroy@example.com"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "#get_users", :vcr do
|
26
|
+
it "returns an array of hashes" do
|
27
|
+
users = client.get_users
|
28
|
+
users.count.should > 1
|
29
|
+
users.should be_a(Array)
|
30
|
+
users.first.should be_a(Hash)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -33,7 +33,8 @@ describe StatRaptor::Client do
|
|
33
33
|
:endpoint => "http://example.com",
|
34
34
|
:timeout => 300,
|
35
35
|
:platform_credentials => "ABC12345",
|
36
|
-
:user_agent => "Fu Manchu Ruby Gem 2.0.0"
|
36
|
+
:user_agent => "Fu Manchu Ruby Gem 2.0.0",
|
37
|
+
:disable_ssl_peer_verification => true
|
37
38
|
}
|
38
39
|
end
|
39
40
|
|
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe StatRaptor do
|
4
|
+
before do
|
5
|
+
StatRaptor.reset
|
6
|
+
end
|
7
|
+
|
4
8
|
after do
|
5
9
|
StatRaptor.reset
|
6
10
|
end
|
@@ -51,12 +55,28 @@ describe StatRaptor do
|
|
51
55
|
end
|
52
56
|
|
53
57
|
describe ".timeout=" do
|
54
|
-
it "should
|
58
|
+
it "should set the timeout" do
|
55
59
|
StatRaptor.timeout = 15
|
56
60
|
StatRaptor.timeout.should == 15
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
64
|
+
describe ".disable_ssl_peer_verification" do
|
65
|
+
it "should return the default setting" do
|
66
|
+
StatRaptor.disable_ssl_peer_verification.should == StatRaptor::Config::DEFAULT_DISABLE_SSL_PEER_VERIFICATION
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe ".disable_ssl_peer_verification=" do
|
71
|
+
it "should set the disable_ssl_peer_verification option" do
|
72
|
+
StatRaptor.disable_ssl_peer_verification = true
|
73
|
+
StatRaptor.disable_ssl_peer_verification.should be_true
|
74
|
+
|
75
|
+
StatRaptor.disable_ssl_peer_verification = false
|
76
|
+
StatRaptor.disable_ssl_peer_verification.should be_false
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
60
80
|
describe ".configure" do
|
61
81
|
StatRaptor::Config::VALID_OPTIONS_KEYS.each do |key|
|
62
82
|
it "should set the #{key}" do
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StatRaptor::Error do
|
4
|
+
context "#initialize" do
|
5
|
+
it "returns an instance of StatRaptor::Error" do
|
6
|
+
StatRaptor::Error.new("message").should be_a(StatRaptor::Error)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "is a subclass of StandardError" do
|
10
|
+
StatRaptor::Error.superclass.should == StandardError
|
11
|
+
end
|
12
|
+
end
|
13
|
+
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-02-
|
11
|
+
s.date = "2012-02-28"
|
12
12
|
s.authors = ["Shay Frendt"]
|
13
13
|
s.email = "shay.frendt@gmail.com"
|
14
14
|
s.homepage = "http://github.com/chargify/statraptor"
|
data/todo.taskpaper
ADDED
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: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
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-02-
|
18
|
+
date: 2012-02-28 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -106,7 +106,7 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - "="
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
hash:
|
109
|
+
hash: -2355515322
|
110
110
|
segments:
|
111
111
|
- 2
|
112
112
|
- 0
|
@@ -206,15 +206,18 @@ files:
|
|
206
206
|
- lib/statraptor/config.rb
|
207
207
|
- lib/statraptor/error.rb
|
208
208
|
- lib/statraptor/error/not_found.rb
|
209
|
+
- lib/statraptor/error/unauthorized.rb
|
209
210
|
- lib/statraptor/version.rb
|
210
|
-
- spec/client/graphs_spec.rb
|
211
|
-
- spec/client/projects_spec.rb
|
212
|
-
- spec/client/user_spec.rb
|
213
|
-
- spec/client_spec.rb
|
214
|
-
- spec/config_spec.rb
|
215
211
|
- spec/spec.opts
|
216
212
|
- spec/spec_helper.rb
|
213
|
+
- spec/statrapator/client/graphs_spec.rb
|
214
|
+
- spec/statrapator/client/projects_spec.rb
|
215
|
+
- spec/statrapator/client/user_spec.rb
|
216
|
+
- spec/statrapator/client_spec.rb
|
217
|
+
- spec/statrapator/config_spec.rb
|
218
|
+
- spec/statrapator/error_spec.rb
|
217
219
|
- statraptor.gemspec
|
220
|
+
- todo.taskpaper
|
218
221
|
has_rdoc: true
|
219
222
|
homepage: http://github.com/chargify/statraptor
|
220
223
|
licenses: []
|
@@ -252,10 +255,11 @@ signing_key:
|
|
252
255
|
specification_version: 3
|
253
256
|
summary: A StatRaptor API wrapper for Ruby
|
254
257
|
test_files:
|
255
|
-
- spec/client/graphs_spec.rb
|
256
|
-
- spec/client/projects_spec.rb
|
257
|
-
- spec/client/user_spec.rb
|
258
|
-
- spec/client_spec.rb
|
259
|
-
- spec/config_spec.rb
|
260
258
|
- spec/spec.opts
|
261
259
|
- spec/spec_helper.rb
|
260
|
+
- spec/statrapator/client/graphs_spec.rb
|
261
|
+
- spec/statrapator/client/projects_spec.rb
|
262
|
+
- spec/statrapator/client/user_spec.rb
|
263
|
+
- spec/statrapator/client_spec.rb
|
264
|
+
- spec/statrapator/config_spec.rb
|
265
|
+
- spec/statrapator/error_spec.rb
|
data/spec/client/graphs_spec.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe StatRaptor::Client::Graphs, :vcr do
|
4
|
-
let(:client) { StatRaptor::Client.new }
|
5
|
-
|
6
|
-
context "#get_revenue_graph_data" do
|
7
|
-
it "returns the revenue graph json" do
|
8
|
-
graph_json = client.get_revenue_graph_data(:user_credentials => user_credentials, :subdomain => chargify_subdomain)
|
9
|
-
graph_json.should == "{\"graph_data\":{\"actual\":[0,0,557,353,360,460,460,552,512,582,282,282,null,null,null,null],\"projected\":[null,null,null,null,null,null,null,null,null,null,null,282,282,282,282,282],\"x_labels\":[\"Feb\",\"Mar\",\"Apr\",\"May\",\"Jun\",\"Jul\",\"Aug\",\"Sep\",\"Oct\",\"Nov\",\"Dec\",\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\"]}}"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "raises an exception if the graph data is not found"
|
13
|
-
end
|
14
|
-
|
15
|
-
context "#get_subscribers_graph_data" do
|
16
|
-
it "returns the subscribers graph json" do
|
17
|
-
graph_json = client.get_subscribers_graph_data(:user_credentials => user_credentials, :subdomain => chargify_subdomain)
|
18
|
-
graph_json.should == "{\"graph_data\":{\"actual\":[0,0,8,8,8,10,10,13,14,16,9,6,null,null,null,null],\"projected\":[null,null,null,null,null,null,null,null,null,null,null,6,4,4,4,4],\"x_labels\":[\"Feb\",\"Mar\",\"Apr\",\"May\",\"Jun\",\"Jul\",\"Aug\",\"Sep\",\"Oct\",\"Nov\",\"Dec\",\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\"]}}"
|
19
|
-
end
|
20
|
-
|
21
|
-
it "raises an exception if the graph data is not found"
|
22
|
-
end
|
23
|
-
|
24
|
-
context "#get_average_lifetime_value_graph_data" do
|
25
|
-
it "returns the average lifetime value graph json" do
|
26
|
-
graph_json = client.get_average_lifetime_value_graph_data(:user_credentials => user_credentials, :subdomain => chargify_subdomain)
|
27
|
-
graph_json.should == "{\"graph_data\":{\"actual\":[0,0,79,102,143,160,202,214,255,244,466,747,null,null,null,null],\"projected\":[null,null,null,null,null,null,null,null,null,null,null,747,1028,1309,1590,1871],\"x_labels\":[\"Feb\",\"Mar\",\"Apr\",\"May\",\"Jun\",\"Jul\",\"Aug\",\"Sep\",\"Oct\",\"Nov\",\"Dec\",\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\"]}}"
|
28
|
-
end
|
29
|
-
|
30
|
-
it "raises an exception if the graph data is not found"
|
31
|
-
end
|
32
|
-
|
33
|
-
context "#get_churn_graph_data" do
|
34
|
-
it "returns the churn graph json" do
|
35
|
-
graph_json = client.get_churn_graph_data(:user_credentials => user_credentials, :subdomain => chargify_subdomain)
|
36
|
-
graph_json.should == "{\"graph_data\":{\"actual\":[0,0,20,0,0,33,0,0,50,0,200,200,null,null,null,null],\"projected\":[null,null,null,null,null,null,null,null,null,null,null,200,200,200,200,200],\"x_labels\":[\"Feb\",\"Mar\",\"Apr\",\"May\",\"Jun\",\"Jul\",\"Aug\",\"Sep\",\"Oct\",\"Nov\",\"Dec\",\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\"]}}"
|
37
|
-
end
|
38
|
-
|
39
|
-
it "raises an exception if the graph data is not found"
|
40
|
-
end
|
41
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe StatRaptor::Client::Projects do
|
4
|
-
let(:client) { StatRaptor::Client.new }
|
5
|
-
|
6
|
-
context "#create_project", :vcr do
|
7
|
-
it "returns the project json on success" do
|
8
|
-
user_json = client.create_user(:email => "zippy@example.com", :chargify_api_key => chargify_api_key)
|
9
|
-
user_hash = JSON.parse(user_json)
|
10
|
-
|
11
|
-
project_json = client.create_project(:user_credentials => user_hash["user_credentials"], :project => {
|
12
|
-
:name => "Zippy Sunday", :subdomain => "zippy-sunday", :component => "basic"
|
13
|
-
})
|
14
|
-
|
15
|
-
project_hash = JSON.parse(project_json)
|
16
|
-
project_hash["name"].should == "Zippy Sunday"
|
17
|
-
project_hash["subdomain"].should == "zippy-sunday"
|
18
|
-
project_hash["component"].should == "basic"
|
19
|
-
end
|
20
|
-
|
21
|
-
it "raises an exception if the project was not created"
|
22
|
-
end
|
23
|
-
|
24
|
-
context "#delete_project", :vcr do
|
25
|
-
it "returns true on success" do
|
26
|
-
user_json = client.create_user(:email => "sammy@example.com", :chargify_api_key => chargify_api_key)
|
27
|
-
user_hash = JSON.parse(user_json)
|
28
|
-
|
29
|
-
project_json = client.create_project(:user_credentials => user_hash["user_credentials"], :project => {
|
30
|
-
:name => "Modern Marvels", :subdomain => "modern-marvels", :component => "advanced"
|
31
|
-
})
|
32
|
-
|
33
|
-
client.delete_project(:user_credentials => user_hash["user_credentials"], :subdomain => "modern-marvels").should be_true
|
34
|
-
end
|
35
|
-
|
36
|
-
it "raises an exception if the project was not deleted" do
|
37
|
-
lambda {
|
38
|
-
client.delete_project(:user_credentials => "abc123", :subdomain => "modern-marvels")
|
39
|
-
}.should raise_error(StatRaptor::Error::NotFound)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
data/spec/client/user_spec.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe StatRaptor::Client::Users do
|
4
|
-
let(:client) { StatRaptor::Client.new }
|
5
|
-
|
6
|
-
context "#create", :vcr do
|
7
|
-
it "returns the user json on success" do
|
8
|
-
user_json = client.create_user(:email => "timmy@example.com", :chargify_api_key => chargify_api_key)
|
9
|
-
user_hash = JSON.parse(user_json)
|
10
|
-
user_hash["user_credentials"].should_not be_nil
|
11
|
-
user_hash["chargify_api_key"].should == chargify_api_key
|
12
|
-
user_hash["email"].should == "timmy@example.com"
|
13
|
-
end
|
14
|
-
|
15
|
-
it "raises an exception if the user was not created"
|
16
|
-
end
|
17
|
-
|
18
|
-
context "#delete_user", :vcr do
|
19
|
-
it "returns true on success" do
|
20
|
-
user_json = client.create_user(:email => "ronny@example.com", :chargify_api_key => chargify_api_key)
|
21
|
-
user_hash = JSON.parse(user_json)
|
22
|
-
client.delete_user(user_hash["user_credentials"]).should be_true
|
23
|
-
end
|
24
|
-
|
25
|
-
it "raises an NotFound exception if the user does not exist" do
|
26
|
-
lambda {
|
27
|
-
client.delete_user("abc123")
|
28
|
-
}.should raise_error(StatRaptor::Error::NotFound)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|