chargify_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/chargify_api.gemspec +68 -0
- data/lib/chargify.rb +15 -0
- data/lib/chargify_api.rb +16 -0
- data/lib/connection.rb +19 -0
- data/lib/list.rb +13 -0
- data/lib/list_item.rb +12 -0
- data/lib/transaction.rb +5 -0
- data/lib/transactions.rb +47 -0
- data/test/helper.rb +18 -0
- data/test/test_chargify_api.rb +7 -0
- metadata +122 -0
data/.document
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
archive-tar-minitar (0.5.2)
|
5
|
+
columnize (0.3.4)
|
6
|
+
crack (0.1.8)
|
7
|
+
git (1.2.5)
|
8
|
+
httparty (0.7.8)
|
9
|
+
crack (= 0.1.8)
|
10
|
+
jeweler (1.6.4)
|
11
|
+
bundler (~> 1.0)
|
12
|
+
git (>= 1.2.5)
|
13
|
+
rake
|
14
|
+
linecache19 (0.5.12)
|
15
|
+
ruby_core_source (>= 0.1.4)
|
16
|
+
rake (0.9.2)
|
17
|
+
rcov (0.9.10)
|
18
|
+
ruby-debug-base19 (0.11.25)
|
19
|
+
columnize (>= 0.3.1)
|
20
|
+
linecache19 (>= 0.5.11)
|
21
|
+
ruby_core_source (>= 0.1.4)
|
22
|
+
ruby-debug19 (0.11.6)
|
23
|
+
columnize (>= 0.3.1)
|
24
|
+
linecache19 (>= 0.5.11)
|
25
|
+
ruby-debug-base19 (>= 0.11.19)
|
26
|
+
ruby_core_source (0.1.5)
|
27
|
+
archive-tar-minitar (>= 0.5.2)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 1.0.0)
|
34
|
+
httparty
|
35
|
+
jeweler (~> 1.6.0)
|
36
|
+
rcov
|
37
|
+
ruby-debug19
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Joshua Abbott
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= chargify_api
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to chargify_api
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Joshua Abbott. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "chargify_api"
|
18
|
+
gem.homepage = "http://github.com/joshnabbott/chargify_api"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A better Chargify API wrapper.}
|
21
|
+
gem.description = %Q{A better Chargify API wrapper,}
|
22
|
+
gem.email = "joshnabbott@gmail.com"
|
23
|
+
gem.authors = ["Joshua Abbott"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "chargify_api #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{chargify_api}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Joshua Abbott}]
|
12
|
+
s.date = %q{2011-08-29}
|
13
|
+
s.description = %q{A better Chargify API wrapper,}
|
14
|
+
s.email = %q{joshnabbott@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"chargify_api.gemspec",
|
28
|
+
"lib/chargify.rb",
|
29
|
+
"lib/chargify_api.rb",
|
30
|
+
"lib/connection.rb",
|
31
|
+
"lib/list.rb",
|
32
|
+
"lib/list_item.rb",
|
33
|
+
"lib/transaction.rb",
|
34
|
+
"lib/transactions.rb",
|
35
|
+
"test/helper.rb",
|
36
|
+
"test/test_chargify_api.rb"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://github.com/joshnabbott/chargify_api}
|
39
|
+
s.licenses = [%q{MIT}]
|
40
|
+
s.require_paths = [%q{lib}]
|
41
|
+
s.rubygems_version = %q{1.8.6}
|
42
|
+
s.summary = %q{A better Chargify API wrapper.}
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
51
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
52
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
55
|
+
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|
56
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
58
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
62
|
+
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|
63
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
64
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
65
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/lib/chargify.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module ChargifyApi
|
2
|
+
class Chargify
|
3
|
+
attr_accessor :connection
|
4
|
+
|
5
|
+
def initialize(api_key, subdomain)
|
6
|
+
@api_key = api_key
|
7
|
+
@subdomain = subdomain
|
8
|
+
@connection = Connection.new(@api_key, @subdomain)
|
9
|
+
end
|
10
|
+
|
11
|
+
def transactions
|
12
|
+
@transactions ||= Transactions.new(self.connection)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/chargify_api.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'ruby-debug'
|
5
|
+
require File.expand_path('../chargify', __FILE__)
|
6
|
+
require File.expand_path('../connection', __FILE__)
|
7
|
+
require File.expand_path('../list', __FILE__)
|
8
|
+
require File.expand_path('../list_item', __FILE__)
|
9
|
+
require File.expand_path('../transaction', __FILE__)
|
10
|
+
require File.expand_path('../transactions', __FILE__)
|
11
|
+
|
12
|
+
module ChargifyApi
|
13
|
+
VERSION = '0.0.1'
|
14
|
+
YAML::ENGINE.yamler = 'syck'
|
15
|
+
end
|
16
|
+
|
data/lib/connection.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module ChargifyApi
|
2
|
+
class Connection
|
3
|
+
attr_accessor :options
|
4
|
+
|
5
|
+
def initialize(api_key, subdomain)
|
6
|
+
@api_key = api_key
|
7
|
+
@subdomain = subdomain
|
8
|
+
@base_url = "https://#{@subdomain}.chargify.com/"
|
9
|
+
end
|
10
|
+
|
11
|
+
def options
|
12
|
+
{ :basic_auth => { :username => @api_key, :password => 'x' } }
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(uri, query_string)
|
16
|
+
HTTParty.get(@base_url + uri, options.merge(:query => query_string))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/list.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module ChargifyApi
|
2
|
+
class List < Array
|
3
|
+
# List#search performs a search on each object in the list
|
4
|
+
# :search_method is the attribute or method you want to search (eg: :name)
|
5
|
+
# :search_term is the term you want to search for (eg: 'Josh')
|
6
|
+
# Search term can be a regular expresion or a string. Search method must be a method
|
7
|
+
# or attribute of the objects in the collection or an undefined method error will be raised.
|
8
|
+
def search(search_method, search_term)
|
9
|
+
self.select { |list_item| list_item.send(search_method) =~ /#{search_term}/i }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
data/lib/list_item.rb
ADDED
data/lib/transaction.rb
ADDED
data/lib/transactions.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module ChargifyApi
|
2
|
+
class Transactions
|
3
|
+
URI = '/transactions.json'
|
4
|
+
|
5
|
+
attr_accessor :uri, :connection
|
6
|
+
|
7
|
+
def initialize(connection)
|
8
|
+
@connection = connection
|
9
|
+
@uri = URI
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns all transactions matching `options` passed
|
13
|
+
# Valid options are:
|
14
|
+
# kinds: An array of transaction types. Must be any of the following:
|
15
|
+
# charge, refund, payment, credit, payment_authorization, info, adjustment
|
16
|
+
# since_id: Returns transactions with an id greater than or equal to the one specified
|
17
|
+
# max_id: Returns transactions with an id less than or equal to the one specified
|
18
|
+
# since_date (format YYYY-MM-DD): Returns transactions with a created_at date greater than or equal to the one specified
|
19
|
+
# until_date (format YYYY-MM-DD): Returns transactions with a created_at date less than or equal to the one specified
|
20
|
+
# page and per_page: The page number and number of results used for pagination. By default results are paginated 20 per page.
|
21
|
+
# A few usage examples:
|
22
|
+
# Last 15 transactions that are "payment" or "payment_authorizations":
|
23
|
+
# @chargify.transactions.get(:kinds => ['payment', 'payment_authorizations'], :per_page => 15)
|
24
|
+
# 50 transactions per page, second page.
|
25
|
+
# @chargify.transactions.get(:page => 2, :per_page => 50)
|
26
|
+
# Last 6 days worth of transactions:
|
27
|
+
# @chargify.transactions.get(:since_date => Date.today - 7, :until_date => Date.today - 1)
|
28
|
+
def get(options = {})
|
29
|
+
self.get_all(options)
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
def get_all(query_string)
|
34
|
+
response = self.connection.get(self.uri, query_string)
|
35
|
+
|
36
|
+
if response.code.to_s =~ /^2\d+$/
|
37
|
+
response.parsed_response.inject(List.new) do |list, item|
|
38
|
+
list << Transaction.new(item['transaction'])
|
39
|
+
list
|
40
|
+
end
|
41
|
+
else
|
42
|
+
raise response.to_s
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'chargify_api'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chargify_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joshua Abbott
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-29 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: &70188512591540 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70188512591540
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: ruby-debug19
|
27
|
+
requirement: &70188512589680 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70188512589680
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
requirement: &70188512588060 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.0.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70188512588060
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: &70188512586280 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.6.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70188512586280
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rcov
|
60
|
+
requirement: &70188512576400 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70188512576400
|
69
|
+
description: A better Chargify API wrapper,
|
70
|
+
email: joshnabbott@gmail.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files:
|
74
|
+
- LICENSE.txt
|
75
|
+
- README.rdoc
|
76
|
+
files:
|
77
|
+
- .document
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.rdoc
|
82
|
+
- Rakefile
|
83
|
+
- VERSION
|
84
|
+
- chargify_api.gemspec
|
85
|
+
- lib/chargify.rb
|
86
|
+
- lib/chargify_api.rb
|
87
|
+
- lib/connection.rb
|
88
|
+
- lib/list.rb
|
89
|
+
- lib/list_item.rb
|
90
|
+
- lib/transaction.rb
|
91
|
+
- lib/transactions.rb
|
92
|
+
- test/helper.rb
|
93
|
+
- test/test_chargify_api.rb
|
94
|
+
homepage: http://github.com/joshnabbott/chargify_api
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: -2291214423344558367
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.6
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: A better Chargify API wrapper.
|
122
|
+
test_files: []
|