statraptor 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg
2
+ .rvmrc
3
+ spec/remote.yml
4
+ spec/cassettes
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - ree
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 0.1.0 (February 13, 2012)
2
+
3
+ Features:
4
+
5
+ - added support for User, Project, and Graph resources
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ # Gem dependencies specified in statraptor.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ statraptor (0.1.0)
5
+ activeresource (>= 2.3.5)
6
+ json (>= 1.4.6)
7
+ typhoeus (>= 0.3.3)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ activemodel (3.2.1)
13
+ activesupport (= 3.2.1)
14
+ builder (~> 3.0.0)
15
+ activeresource (3.2.1)
16
+ activemodel (= 3.2.1)
17
+ activesupport (= 3.2.1)
18
+ activesupport (3.2.1)
19
+ i18n (~> 0.6)
20
+ multi_json (~> 1.0)
21
+ addressable (2.2.6)
22
+ builder (3.0.0)
23
+ crack (0.3.1)
24
+ diff-lcs (1.1.3)
25
+ ffi (1.0.11)
26
+ growl (1.0.3)
27
+ guard (1.0.0)
28
+ ffi (>= 0.5.0)
29
+ thor (~> 0.14.6)
30
+ guard-rspec (0.6.0)
31
+ guard (>= 0.10.0)
32
+ i18n (0.6.0)
33
+ json (1.6.5)
34
+ mime-types (1.17.2)
35
+ multi_json (1.0.4)
36
+ rake (0.9.2.2)
37
+ rb-fsevent (0.9.0)
38
+ rspec (2.8.0)
39
+ rspec-core (~> 2.8.0)
40
+ rspec-expectations (~> 2.8.0)
41
+ rspec-mocks (~> 2.8.0)
42
+ rspec-core (2.8.0)
43
+ rspec-expectations (2.8.0)
44
+ diff-lcs (~> 1.1.2)
45
+ rspec-mocks (2.8.0)
46
+ thor (0.14.6)
47
+ typhoeus (0.3.3)
48
+ mime-types
49
+ vcr (2.0.0.rc1)
50
+ webmock (1.7.10)
51
+ addressable (~> 2.2, > 2.2.5)
52
+ crack (>= 0.1.7)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ growl (~> 1.0.3)
59
+ guard-rspec (~> 0.6.0)
60
+ rake (~> 0.9.2)
61
+ rb-fsevent (~> 0.9.0)
62
+ rspec (~> 2.8.0)
63
+ statraptor!
64
+ vcr (= 2.0.0.rc1)
65
+ webmock (= 1.7.10)
data/Guardfile ADDED
@@ -0,0 +1,14 @@
1
+ # Run me with:
2
+ #
3
+ # $ bundle exec guard
4
+
5
+ begin
6
+ require 'rb-inotify'
7
+ require 'libnotify'
8
+ rescue LoadError
9
+ end
10
+
11
+ guard 'rspec', :all_on_start => false, :all_after_pass => false do
12
+ watch(%r{^spec/.+_spec\.rb})
13
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
14
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2012 Chargify LLC
2
+
3
+ The MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ StatRaptor API wrapper for Ruby [![build status](https://secure.travis-ci.org/chargify/statraptor.png)](http://travis-ci.org/chargify/statraptor)
2
+ ===============================
3
+
4
+ Interact with client like so:
5
+
6
+ ``` ruby
7
+ # Configure the library to use your
8
+ # StatRaptor platform credentials
9
+
10
+ StatRaptor.configure do |config|
11
+ config.platform_credentials = "ABC123"
12
+ end
13
+
14
+ # Initialize a client
15
+ client = StatRaptor::Client.new
16
+
17
+ # Manage users
18
+ client.create_user(:email => "timmy@example.com", :chargify_api_key => "XYZ456")
19
+ client.delete_user("akskd8328389281728918")
20
+
21
+ # Manage projects
22
+ client.create_project(:user_credentials => "3892839akslje",
23
+ :project => {:name => "Zippy", :subdomain => "zippy-llc", :component => "advanced"})
24
+ client.delete_project(:user_credentials => "3892839akslje", :subdomain => "zippy-llc")
25
+
26
+ # Graphs
27
+ client.get_revenue_graph_data(:user_credentials => "3892839akslje", :subdomain => "zippy-llc")
28
+ client.get_subscribers_graph_data(:user_credentials => "3892839akslje", :subdomain => "zippy-llc")
29
+ client.get_average_lifetime_value_graph_data(:user_credentials => "3892839akslje", :subdomain => "zippy-llc")
30
+ client.get_churn_graph_data(:user_credentials => "3892839akslje", :subdomain => "zippy-llc")
31
+ ```
32
+
33
+ ### Installation
34
+
35
+ You can install this library as a gem using the following command:
36
+
37
+ ```
38
+ $ gem install statraptor
39
+ ```
40
+
41
+ If you're using Rails, include the gem in your Gemfile:
42
+
43
+ ``` ruby
44
+ gem 'statraptor'
45
+ ```
46
+
47
+ ### Resources
48
+
49
+ The following resources exist for interacting with the StatRaptor API:
50
+
51
+ * `StatRaptor::Client::Users`
52
+ * `StatRaptor::Client::Projects`
53
+ * `StatRaptor::Client::Graphs`
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.pattern = FileList['spec/**/*_spec.rb']
7
+ end
8
+
9
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ module StatRaptor
2
+ class Client
3
+ module Graphs
4
+ def get_revenue_graph_data(params={})
5
+ graph_data("revenue", params)
6
+ end
7
+
8
+ def get_subscribers_graph_data(params={})
9
+ graph_data("subscribers", params)
10
+ end
11
+
12
+ def get_average_lifetime_value_graph_data(params={})
13
+ graph_data("average_lifetime_value", params)
14
+ end
15
+
16
+ def get_churn_graph_data(params={})
17
+ graph_data("churn", params)
18
+ end
19
+
20
+ private
21
+
22
+ def graph_data(type, params={})
23
+ response = Typhoeus::Request.get("#{StatRaptor.endpoint}/graphs/#{type}", :params => params)
24
+ response.body
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ module StatRaptor
2
+ class Client
3
+ module Projects
4
+ def create_project(params={})
5
+ response = Typhoeus::Request.post("#{StatRaptor.endpoint}/projects", :params => {:platform_credentials => StatRaptor.platform_credentials, :user_credentials => params[:user_credentials], :project => params[:project]})
6
+ response.body
7
+ end
8
+
9
+ def delete_project(params={})
10
+ response = Typhoeus::Request.delete("#{StatRaptor.endpoint}/projects/#{params[:subdomain]}", :params => {:platform_credentials => StatRaptor.platform_credentials, :user_credentials => params[:user_credentials]})
11
+ handle_response(response)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ require 'statraptor/error/not_found'
2
+
3
+ module StatRaptor
4
+ class Client
5
+ module Users
6
+ def create_user(params={})
7
+ response = Typhoeus::Request.post("#{StatRaptor.endpoint}/users", :params => {:platform_credentials => StatRaptor.platform_credentials, :user => params })
8
+ response.body
9
+ end
10
+
11
+ def delete_user(user_credentials)
12
+ response = Typhoeus::Request.delete("#{StatRaptor.endpoint}/users/#{user_credentials}", :params => {:platform_credentials => StatRaptor.platform_credentials})
13
+ handle_response(response)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,40 @@
1
+ require 'statraptor/config'
2
+ require 'statraptor/error'
3
+
4
+ module StatRaptor
5
+ class Client
6
+
7
+ require 'statraptor/client/users'
8
+ include StatRaptor::Client::Users
9
+
10
+ require 'statraptor/client/projects'
11
+ include StatRaptor::Client::Projects
12
+
13
+ require 'statraptor/client/graphs'
14
+ include StatRaptor::Client::Graphs
15
+
16
+ attr_accessor *Config::VALID_OPTIONS_KEYS
17
+
18
+ # Initializes a new API object
19
+ #
20
+ # @param attrs [Hash]
21
+ # @return [StatRaptor::Client]
22
+ def initialize(attrs={})
23
+ attrs = StatRaptor.options.merge(attrs)
24
+ Config::VALID_OPTIONS_KEYS.each do |key|
25
+ instance_variable_set("@#{key}".to_sym, attrs[key])
26
+ end
27
+ end
28
+
29
+ def handle_response(response)
30
+ case response.code
31
+ when 200
32
+ return true
33
+ when 422
34
+ message = JSON.parse(response.body)["errors"].join(",")
35
+ raise StatRaptor::Error::NotFound.new(message)
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,57 @@
1
+ require 'statraptor/version'
2
+
3
+ module StatRaptor
4
+ # Defines constants and methods related to configuration
5
+ # Inspired by the Twitter gem config: http://bit.ly/A2RPvv
6
+ module Config
7
+
8
+ # The endpoint that will be used to connect if none is set
9
+ DEFAULT_ENDPOINT = "https://statraptor.com/api/v1"
10
+
11
+ # The value sent in the 'User-Agent' header if none is set
12
+ DEFAULT_USER_AGENT = "StatRaptor Ruby Gem #{StatRaptor::VERSION}"
13
+
14
+ # The timeout in seconds that will be used if none is set
15
+ DEFAULT_TIMEOUT = 2
16
+
17
+ # The default platform_credentials if none are set
18
+ DEFAULT_PLATFORM_CREDENTIALS = nil
19
+
20
+ # An array of valid keys in the options hash when configuring a {StatRaptor::Client}
21
+ VALID_OPTIONS_KEYS = [
22
+ :endpoint,
23
+ :user_agent,
24
+ :timeout,
25
+ :platform_credentials
26
+ ]
27
+
28
+ attr_accessor *VALID_OPTIONS_KEYS
29
+
30
+ # When this module is extended, set all configuration options to their default values
31
+ def self.extended(base)
32
+ base.reset
33
+ end
34
+
35
+ # Convenience method to allow configuration options to be set in a block
36
+ def configure
37
+ yield self
38
+ self
39
+ end
40
+
41
+ # Create a hash of options and their values
42
+ def options
43
+ options = {}
44
+ VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
45
+ options
46
+ end
47
+
48
+ # Reset all configuration options to defaults
49
+ def reset
50
+ self.endpoint = DEFAULT_ENDPOINT
51
+ self.user_agent = DEFAULT_USER_AGENT
52
+ self.timeout = DEFAULT_TIMEOUT
53
+ self.platform_credentials = DEFAULT_PLATFORM_CREDENTIALS
54
+ self
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,5 @@
1
+ module StatRaptor
2
+ # Raised when StatRaptor returns the HTTP status code 404
3
+ class Error::NotFound < StatRaptor::Error
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ module StatRaptor
2
+ # Custom error class for rescuing from all StatRaptor errors
3
+ class Error < StandardError
4
+
5
+ # Initializes a new Error object
6
+ #
7
+ # @param message [String]
8
+ # @return [StatRaptor::Error]
9
+ def initialize(message)
10
+ super(message)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module StatRaptor
2
+ VERSION = "0.1.0"
3
+ end
data/lib/statraptor.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'typhoeus'
3
+ require 'json'
4
+ require 'statraptor/version'
5
+ require 'statraptor/config'
6
+ require 'statraptor/client'
7
+
8
+ module StatRaptor
9
+ extend Config
10
+ end
@@ -0,0 +1,41 @@
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
@@ -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
+ 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
@@ -0,0 +1,31 @@
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
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe StatRaptor::Client do
4
+ before do
5
+ @keys = StatRaptor::Config::VALID_OPTIONS_KEYS
6
+ end
7
+
8
+ context "with module configuration" do
9
+ before do
10
+ StatRaptor.configure do |config|
11
+ @keys.each do |key|
12
+ config.send("#{key}=", key)
13
+ end
14
+ end
15
+ end
16
+
17
+ after do
18
+ StatRaptor.reset
19
+ end
20
+
21
+ it "should inherit module configuration" do
22
+ client = StatRaptor::Client.new
23
+
24
+ @keys.each do |key|
25
+ client.send(key).should == key
26
+ end
27
+ end
28
+ end
29
+
30
+ context "with class configuration" do
31
+ before do
32
+ @configuration = {
33
+ :endpoint => "http://example.com",
34
+ :timeout => 300,
35
+ :platform_credentials => "ABC12345",
36
+ :user_agent => "Fu Manchu Ruby Gem 2.0.0"
37
+ }
38
+ end
39
+
40
+ context "during initialization" do
41
+ it "should override module configuration" do
42
+ client = StatRaptor::Client.new(@configuration)
43
+ @keys.each do |key|
44
+ client.send(key).should == @configuration[key]
45
+ end
46
+ end
47
+ end
48
+
49
+ context "after initialization" do
50
+ it "should override module configuration" do
51
+ client = StatRaptor::Client.new
52
+ @configuration.each do |key, value|
53
+ client.send("#{key}=", value)
54
+ end
55
+
56
+ @keys.each do |key|
57
+ client.send(key).should == @configuration[key]
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe StatRaptor do
4
+ after do
5
+ StatRaptor.reset
6
+ end
7
+
8
+ describe ".endpoint" do
9
+ it "should return the default endpoint" do
10
+ StatRaptor.endpoint.should == StatRaptor::Config::DEFAULT_ENDPOINT
11
+ end
12
+ end
13
+
14
+ describe ".endpoint=" do
15
+ it "should set the endpoint" do
16
+ StatRaptor.endpoint = 'http://example.com/'
17
+ StatRaptor.endpoint.should == 'http://example.com/'
18
+ end
19
+ end
20
+
21
+ describe ".user_agent" do
22
+ it "should return the default user agent" do
23
+ StatRaptor.user_agent.should == StatRaptor::Config::DEFAULT_USER_AGENT
24
+ end
25
+ end
26
+
27
+ describe ".user_agent=" do
28
+ it "should set the user_agent" do
29
+ StatRaptor.user_agent = 'Custom User Agent'
30
+ StatRaptor.user_agent.should == 'Custom User Agent'
31
+ end
32
+ end
33
+
34
+ describe ".platform_credentials" do
35
+ it "should return the default platform_credentials" do
36
+ StatRaptor.platform_credentials.should == StatRaptor::Config::DEFAULT_PLATFORM_CREDENTIALS
37
+ end
38
+ end
39
+
40
+ describe ".platform_credentials=" do
41
+ it "should set the platform_credentials" do
42
+ StatRaptor.platform_credentials = "ABC123"
43
+ StatRaptor.platform_credentials.should == "ABC123"
44
+ end
45
+ end
46
+
47
+ describe ".timeout" do
48
+ it "should return the default timeout" do
49
+ StatRaptor.timeout.should == StatRaptor::Config::DEFAULT_TIMEOUT
50
+ end
51
+ end
52
+
53
+ describe ".timeout=" do
54
+ it "should return the timeout" do
55
+ StatRaptor.timeout = 15
56
+ StatRaptor.timeout.should == 15
57
+ end
58
+ end
59
+
60
+ describe ".configure" do
61
+ StatRaptor::Config::VALID_OPTIONS_KEYS.each do |key|
62
+ it "should set the #{key}" do
63
+ StatRaptor.configure do |config|
64
+ config.send("#{key}=", key)
65
+ StatRaptor.send(key).should == key
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format progress
@@ -0,0 +1,58 @@
1
+ $:.unshift File.expand_path('../lib', File.dirname(__FILE__))
2
+
3
+ require 'statraptor'
4
+ require 'rspec'
5
+ require 'vcr'
6
+ require 'webmock/rspec'
7
+ require 'yaml'
8
+
9
+ unless File.exists?(File.join(File.dirname(__FILE__), 'remote.yml'))
10
+ STDERR.puts "\nERROR: Make sure a remote.yml file exists at ./spec/remote.yml\n\n"
11
+ abort
12
+ end
13
+
14
+ RSpec.configure do |config|
15
+ config.filter_run :focused => true
16
+ config.run_all_when_everything_filtered = true
17
+ config.alias_example_to :fit, :focused => true
18
+ config.color_enabled = true
19
+
20
+ # so we can use `:vcr` rathaner than `:vcr => true`;
21
+ # in RSpec 3 this will no longer be necessary.
22
+ config.treat_symbols_as_metadata_keys_with_true_values = true
23
+
24
+ config.before(:all) do
25
+ StatRaptor.configure do |config|
26
+ config.platform_credentials = platform_credentials
27
+ end
28
+ end
29
+ end
30
+
31
+ VCR.configure do |config|
32
+ config.hook_into :webmock
33
+ config.cassette_library_dir = 'spec/cassettes'
34
+ config.configure_rspec_metadata!
35
+ config.default_cassette_options = {:record => :new_episodes, :match_requests_on => [:uri, :body, :headers]}
36
+ end
37
+
38
+ def platform_credentials
39
+ remote_configuration["platform_credentials"]
40
+ end
41
+
42
+ def chargify_api_key
43
+ remote_configuration["chargify_api_key"]
44
+ end
45
+
46
+ def chargify_subdomain
47
+ remote_configuration["subdomain"]
48
+ end
49
+
50
+ def user_credentials
51
+ remote_configuration["user_credentials"]
52
+ end
53
+
54
+ private
55
+
56
+ def remote_configuration
57
+ @remote_configuration ||= YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), 'remote.yml')))
58
+ end
@@ -0,0 +1,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+
5
+ require 'statraptor/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "statraptor"
9
+ s.version = StatRaptor::VERSION
10
+ s.platform = Gem::Platform::RUBY
11
+ s.date = "2012-02-24"
12
+ s.authors = ["Shay Frendt"]
13
+ s.email = "shay.frendt@gmail.com"
14
+ s.homepage = "http://github.com/chargify/statraptor"
15
+ s.summary = "A StatRaptor API wrapper for Ruby"
16
+ s.description = "StatRaptor gathers all your metrics into one simple-to-use dashboard."
17
+
18
+ s.required_rubygems_version = ">= 1.3.6"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.require_paths = ['lib']
23
+
24
+ # Runtime Dependencies
25
+ s.add_runtime_dependency('activeresource', '>= 2.3.5')
26
+ s.add_runtime_dependency('typhoeus', '>= 0.3.3')
27
+ s.add_runtime_dependency('json', '>= 1.4.6')
28
+
29
+ # Development Dependencies
30
+ s.add_development_dependency('rake', '~> 0.9.2')
31
+ s.add_development_dependency('rspec', '~> 2.8.0')
32
+ s.add_development_dependency('vcr', '2.0.0.rc1')
33
+ s.add_development_dependency('webmock', '1.7.10')
34
+ s.add_development_dependency('guard-rspec', '~> 0.6.0')
35
+ s.add_development_dependency('growl', '~> 1.0.3')
36
+ s.add_development_dependency('rb-fsevent', '~> 0.9.0')
37
+ end
metadata ADDED
@@ -0,0 +1,261 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statraptor
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Shay Frendt
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-24 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activeresource
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 9
30
+ segments:
31
+ - 2
32
+ - 3
33
+ - 5
34
+ version: 2.3.5
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: typhoeus
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 21
46
+ segments:
47
+ - 0
48
+ - 3
49
+ - 3
50
+ version: 0.3.3
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: json
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 11
62
+ segments:
63
+ - 1
64
+ - 4
65
+ - 6
66
+ version: 1.4.6
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ hash: 63
78
+ segments:
79
+ - 0
80
+ - 9
81
+ - 2
82
+ version: 0.9.2
83
+ type: :development
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: rspec
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ hash: 47
94
+ segments:
95
+ - 2
96
+ - 8
97
+ - 0
98
+ version: 2.8.0
99
+ type: :development
100
+ version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ name: vcr
103
+ prerelease: false
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - "="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3424234125
110
+ segments:
111
+ - 2
112
+ - 0
113
+ - 0
114
+ - rc
115
+ - 1
116
+ version: 2.0.0.rc1
117
+ type: :development
118
+ version_requirements: *id006
119
+ - !ruby/object:Gem::Dependency
120
+ name: webmock
121
+ prerelease: false
122
+ requirement: &id007 !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - "="
126
+ - !ruby/object:Gem::Version
127
+ hash: 31
128
+ segments:
129
+ - 1
130
+ - 7
131
+ - 10
132
+ version: 1.7.10
133
+ type: :development
134
+ version_requirements: *id007
135
+ - !ruby/object:Gem::Dependency
136
+ name: guard-rspec
137
+ prerelease: false
138
+ requirement: &id008 !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ~>
142
+ - !ruby/object:Gem::Version
143
+ hash: 7
144
+ segments:
145
+ - 0
146
+ - 6
147
+ - 0
148
+ version: 0.6.0
149
+ type: :development
150
+ version_requirements: *id008
151
+ - !ruby/object:Gem::Dependency
152
+ name: growl
153
+ prerelease: false
154
+ requirement: &id009 !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ~>
158
+ - !ruby/object:Gem::Version
159
+ hash: 17
160
+ segments:
161
+ - 1
162
+ - 0
163
+ - 3
164
+ version: 1.0.3
165
+ type: :development
166
+ version_requirements: *id009
167
+ - !ruby/object:Gem::Dependency
168
+ name: rb-fsevent
169
+ prerelease: false
170
+ requirement: &id010 !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ~>
174
+ - !ruby/object:Gem::Version
175
+ hash: 59
176
+ segments:
177
+ - 0
178
+ - 9
179
+ - 0
180
+ version: 0.9.0
181
+ type: :development
182
+ version_requirements: *id010
183
+ description: StatRaptor gathers all your metrics into one simple-to-use dashboard.
184
+ email: shay.frendt@gmail.com
185
+ executables: []
186
+
187
+ extensions: []
188
+
189
+ extra_rdoc_files: []
190
+
191
+ files:
192
+ - .gitignore
193
+ - .travis.yml
194
+ - CHANGELOG.md
195
+ - Gemfile
196
+ - Gemfile.lock
197
+ - Guardfile
198
+ - LICENSE
199
+ - README.md
200
+ - Rakefile
201
+ - lib/statraptor.rb
202
+ - lib/statraptor/client.rb
203
+ - lib/statraptor/client/graphs.rb
204
+ - lib/statraptor/client/projects.rb
205
+ - lib/statraptor/client/users.rb
206
+ - lib/statraptor/config.rb
207
+ - lib/statraptor/error.rb
208
+ - lib/statraptor/error/not_found.rb
209
+ - 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
+ - spec/spec.opts
216
+ - spec/spec_helper.rb
217
+ - statraptor.gemspec
218
+ has_rdoc: true
219
+ homepage: http://github.com/chargify/statraptor
220
+ licenses: []
221
+
222
+ post_install_message:
223
+ rdoc_options: []
224
+
225
+ require_paths:
226
+ - lib
227
+ required_ruby_version: !ruby/object:Gem::Requirement
228
+ none: false
229
+ requirements:
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ hash: 3
233
+ segments:
234
+ - 0
235
+ version: "0"
236
+ required_rubygems_version: !ruby/object:Gem::Requirement
237
+ none: false
238
+ requirements:
239
+ - - ">="
240
+ - !ruby/object:Gem::Version
241
+ hash: 23
242
+ segments:
243
+ - 1
244
+ - 3
245
+ - 6
246
+ version: 1.3.6
247
+ requirements: []
248
+
249
+ rubyforge_project:
250
+ rubygems_version: 1.6.2
251
+ signing_key:
252
+ specification_version: 3
253
+ summary: A StatRaptor API wrapper for Ruby
254
+ 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
+ - spec/spec.opts
261
+ - spec/spec_helper.rb