invoiced 0.0.2
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 +7 -0
- data/.gitignore +3 -0
- data/.travis.yml +9 -0
- data/Gemfile +6 -0
- data/README.md +55 -0
- data/Rakefile +9 -0
- data/invoiced.gemspec +29 -0
- data/lib/invoiced/customer.rb +8 -0
- data/lib/invoiced/error/api_error.rb +5 -0
- data/lib/invoiced/error/authentication_error.rb +5 -0
- data/lib/invoiced/error/error_base.rb +17 -0
- data/lib/invoiced/error/invalid_request.rb +5 -0
- data/lib/invoiced/invoice.rb +8 -0
- data/lib/invoiced/list.rb +27 -0
- data/lib/invoiced/object.rb +137 -0
- data/lib/invoiced/operations/create.rb +11 -0
- data/lib/invoiced/operations/delete.rb +13 -0
- data/lib/invoiced/operations/list.rb +17 -0
- data/lib/invoiced/operations/update.rb +12 -0
- data/lib/invoiced/plan.rb +8 -0
- data/lib/invoiced/subscription.rb +8 -0
- data/lib/invoiced/transaction.rb +8 -0
- data/lib/invoiced/util.rb +65 -0
- data/lib/invoiced/version.rb +3 -0
- data/lib/invoiced.rb +145 -0
- data/test/invoiced/customer_test.rb +28 -0
- data/test/invoiced/invoiced_test.rb +24 -0
- data/test/invoiced/util_test.rb +37 -0
- data/test/test_helper.rb +12 -0
- metadata +174 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cc194f9f859feabac87cb4221ba885b044186904
|
4
|
+
data.tar.gz: e97ae96cbecb71e659c1c225acd705032ca8e2cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b3ffe7b5e73a88dc759458614f13aad31b9d322b8bc11d20f88dda22f43df6b70114197572e78356a419bbf0a0be8d7ddc8f8fd928c4bd2e2b11330c3aa5e03
|
7
|
+
data.tar.gz: 98f497695139a6c389ff31d221eb12911989522ff63fa44ea4c61eef1180bd61124c67e9f6e5fc2842f97aaaceb4f7c0a1b20361107248ec35338b2e6bf49c90
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
invoiced-ruby
|
2
|
+
========
|
3
|
+
|
4
|
+
This repository contains the Ruby client library for the [Invoiced](https://invoiced.com) API.
|
5
|
+
|
6
|
+
## Installing
|
7
|
+
|
8
|
+
The Invoiced gem can be installed liked this:
|
9
|
+
|
10
|
+
```
|
11
|
+
gem install invoiced
|
12
|
+
```
|
13
|
+
|
14
|
+
It can be added to your Gemfile:
|
15
|
+
|
16
|
+
```
|
17
|
+
source 'https://rubygems.org'
|
18
|
+
|
19
|
+
gem 'invoiced'
|
20
|
+
```
|
21
|
+
|
22
|
+
## Requirements
|
23
|
+
|
24
|
+
- >= Ruby 1.9.3
|
25
|
+
- rest_client, json, and active_support gems
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
First, you must instantiate a new client
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'invoiced'
|
33
|
+
|
34
|
+
invoiced = Invoiced::Client.new("{API_KEY}")
|
35
|
+
```
|
36
|
+
|
37
|
+
Then, API calls can be made like this:
|
38
|
+
```ruby
|
39
|
+
invoice = invoiced.Invoice.retrieve("{INVOICE_ID}")
|
40
|
+
|
41
|
+
transaction = invoiced.Transaction.create(
|
42
|
+
:invoice => invoice.id,
|
43
|
+
:amount => invoice.balance,
|
44
|
+
:method => "check")
|
45
|
+
```
|
46
|
+
|
47
|
+
## Developing
|
48
|
+
|
49
|
+
The gem can be built with:
|
50
|
+
|
51
|
+
```
|
52
|
+
gem build invoiced.gemspec
|
53
|
+
```
|
54
|
+
|
55
|
+
The test suite can be ran with `rake test`
|
data/Rakefile
ADDED
data/invoiced.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
2
|
+
|
3
|
+
require 'invoiced/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'invoiced'
|
7
|
+
s.version = Invoiced::VERSION
|
8
|
+
s.licenses = ['MIT']
|
9
|
+
s.summary = "Ruby client library for the Invoiced API"
|
10
|
+
s.description = "Invoiced makes invoicing and recurring billing dead simple"
|
11
|
+
s.authors = ["Jared King"]
|
12
|
+
s.email = 'api@invoiced.com'
|
13
|
+
s.files = ["lib/invoiced.rb"]
|
14
|
+
s.homepage = 'https://developers.invoiced.com'
|
15
|
+
s.required_ruby_version = '>= 1.9.3'
|
16
|
+
|
17
|
+
s.add_dependency('rest-client', '~> 1.8.0')
|
18
|
+
s.add_dependency('json', '~> 1.8.3')
|
19
|
+
s.add_dependency('activesupport', '~> 4.2.3')
|
20
|
+
|
21
|
+
s.add_development_dependency('mocha', '~> 0.13.2')
|
22
|
+
s.add_development_dependency('shoulda', '~> 3.4.0')
|
23
|
+
s.add_development_dependency('test-unit')
|
24
|
+
s.add_development_dependency('rake')
|
25
|
+
|
26
|
+
s.files = `git ls-files`.split("\n")
|
27
|
+
s.test_files = `git ls-files -- test/*`.split("\n")
|
28
|
+
s.require_paths = ['lib']
|
29
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Invoiced
|
2
|
+
class ErrorBase < StandardError
|
3
|
+
attr_reader :message
|
4
|
+
attr_reader :status_code
|
5
|
+
attr_reader :error
|
6
|
+
|
7
|
+
def initialize(message=nil, status_code=nil, error=nil)
|
8
|
+
@message = message
|
9
|
+
@status_code = status_code
|
10
|
+
@error = error
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"(#{@status_code}): #{@message}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Invoiced
|
2
|
+
class List
|
3
|
+
attr_reader :links
|
4
|
+
attr_reader :total_count
|
5
|
+
|
6
|
+
def initialize(link_header, total_count)
|
7
|
+
@links = parse_link_header(link_header)
|
8
|
+
@total_count = total_count
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def parse_link_header(header)
|
14
|
+
links = Hash.new
|
15
|
+
|
16
|
+
# Parse each part into a named link
|
17
|
+
header.split(',').each do |part, index|
|
18
|
+
section = part.split(';')
|
19
|
+
url = section[0][/<(.*)>/,1]
|
20
|
+
name = section[1][/rel="(.*)"/,1].to_sym
|
21
|
+
links[name] = url
|
22
|
+
end
|
23
|
+
|
24
|
+
return links
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
module Invoiced
|
2
|
+
class Object
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :client
|
6
|
+
|
7
|
+
@@permanent_attributes = Set.new([:id])
|
8
|
+
|
9
|
+
def initialize(client, id=nil, values={})
|
10
|
+
@client = client
|
11
|
+
class_name = self.class.name.split('::').last
|
12
|
+
@endpoint = '/' + class_name.underscore.pluralize.downcase
|
13
|
+
|
14
|
+
@id = id
|
15
|
+
@values = {}
|
16
|
+
|
17
|
+
if !id.nil?
|
18
|
+
@endpoint += "/#{id}"
|
19
|
+
@values = values.dup.merge({:id => id})
|
20
|
+
@unsaved = Set.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def retrieve(id, opts={})
|
25
|
+
if !id
|
26
|
+
raise ArgumentError.new("Missing ID.")
|
27
|
+
end
|
28
|
+
|
29
|
+
response = @client.request(:get, "#{@endpoint}/#{id}", opts)
|
30
|
+
|
31
|
+
self.class.new(@client, id, response[:body])
|
32
|
+
end
|
33
|
+
|
34
|
+
def load(opts={})
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s(*args)
|
38
|
+
JSON.pretty_generate(@values)
|
39
|
+
end
|
40
|
+
|
41
|
+
def inspect
|
42
|
+
id_string = (!@id.nil?) ? " id=#{@id}" : ""
|
43
|
+
"#<#{self.class}:0x#{self.object_id.to_s(16)}#{id_string}> JSON: " + JSON.pretty_generate(@values)
|
44
|
+
end
|
45
|
+
|
46
|
+
def [](k)
|
47
|
+
@values[k.to_sym]
|
48
|
+
end
|
49
|
+
|
50
|
+
def []=(k, v)
|
51
|
+
send(:"#{k}=", v)
|
52
|
+
end
|
53
|
+
|
54
|
+
def keys
|
55
|
+
@values.keys
|
56
|
+
end
|
57
|
+
|
58
|
+
def values
|
59
|
+
@values.values
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_json(*a)
|
63
|
+
JSON.generate(@values)
|
64
|
+
end
|
65
|
+
|
66
|
+
def as_json(*a)
|
67
|
+
@values.as_json(*a)
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_hash
|
71
|
+
@values.inject({}) do |acc, (key, value)|
|
72
|
+
acc[key] = value.respond_to?(:to_hash) ? value.to_hash : value
|
73
|
+
acc
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def each(&blk)
|
78
|
+
@values.each(&blk)
|
79
|
+
end
|
80
|
+
|
81
|
+
def metaclass
|
82
|
+
class << self; self; end
|
83
|
+
end
|
84
|
+
|
85
|
+
def remove_accessors(keys)
|
86
|
+
metaclass.instance_eval do
|
87
|
+
keys.each do |k|
|
88
|
+
next if @@permanent_attributes.include?(k)
|
89
|
+
k_eq = :"#{k}="
|
90
|
+
remove_method(k) if method_defined?(k)
|
91
|
+
remove_method(k_eq) if method_defined?(k_eq)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def add_accessors(keys)
|
97
|
+
metaclass.instance_eval do
|
98
|
+
keys.each do |k|
|
99
|
+
next if @@permanent_attributes.include?(k)
|
100
|
+
k_eq = :"#{k}="
|
101
|
+
define_method(k) { @values[k] }
|
102
|
+
define_method(k_eq) do |v|
|
103
|
+
if v == ""
|
104
|
+
raise ArgumentError.new(
|
105
|
+
"You cannot set #{k} to an empty string." \
|
106
|
+
"We interpret empty strings as nil in requests." \
|
107
|
+
"You may set #{self}.#{k} = nil to delete the property.")
|
108
|
+
end
|
109
|
+
@values[k] = v
|
110
|
+
@unsaved.add(k)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def method_missing(name, *args)
|
117
|
+
if name.to_s.end_with?('=')
|
118
|
+
attr = name.to_s[0...-1].to_sym
|
119
|
+
add_accessors([attr])
|
120
|
+
begin
|
121
|
+
mth = method(name)
|
122
|
+
rescue NameError
|
123
|
+
raise NoMethodError.new("Cannot set #{attr} on this object. HINT: you can't set: #{@@permanent_attributes.to_a.join(', ')}")
|
124
|
+
end
|
125
|
+
return mth.call(args[0])
|
126
|
+
else
|
127
|
+
return @values[name] if @values.has_key?(name)
|
128
|
+
end
|
129
|
+
|
130
|
+
begin
|
131
|
+
super
|
132
|
+
rescue NoMethodError => e
|
133
|
+
raise
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Invoiced
|
2
|
+
module Operations
|
3
|
+
module List
|
4
|
+
def list(opts={})
|
5
|
+
response = @client.request(:get, @endpoint, opts)
|
6
|
+
|
7
|
+
# build objects
|
8
|
+
objects = Util.build_objects(self, response[:body])
|
9
|
+
|
10
|
+
# store the metadata from the list operation
|
11
|
+
metadata = Invoiced::List.new(response[:headers][:link], response[:headers][:x_total_count])
|
12
|
+
|
13
|
+
return objects, metadata
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Invoiced
|
2
|
+
class Util
|
3
|
+
class << self
|
4
|
+
def auth_header(api_key)
|
5
|
+
"Basic " + Base64.strict_encode64(api_key + ":")
|
6
|
+
end
|
7
|
+
|
8
|
+
def uri_encode(params)
|
9
|
+
flatten_params(params).
|
10
|
+
map { |k,v| "#{k}=#{url_encode(v)}" }.join('&')
|
11
|
+
end
|
12
|
+
|
13
|
+
def build_objects(_class, objects)
|
14
|
+
objects.map {
|
15
|
+
|object| convert_to_object(_class, object)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def convert_to_object(_class, object)
|
20
|
+
_class.class.new(_class.client, object[:id], object)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def url_encode(params)
|
26
|
+
if params.is_a?(Hash)
|
27
|
+
params.map {
|
28
|
+
|k,v| "#{k}=#{uri_encode(v)}"
|
29
|
+
}.join('&')
|
30
|
+
else
|
31
|
+
URI.escape(params.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def flatten_params(params, parent_key=nil)
|
36
|
+
result = []
|
37
|
+
params.each do |key, value|
|
38
|
+
calculated_key = parent_key ? "#{parent_key}[#{url_encode(key)}]" : url_encode(key)
|
39
|
+
if value.is_a?(Hash)
|
40
|
+
result += flatten_params(value, calculated_key)
|
41
|
+
elsif value.is_a?(Array)
|
42
|
+
result += flatten_params_array(value, calculated_key)
|
43
|
+
else
|
44
|
+
result << [calculated_key, value]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
result
|
48
|
+
end
|
49
|
+
|
50
|
+
def flatten_params_array(value, calculated_key)
|
51
|
+
result = []
|
52
|
+
value.each do |elem|
|
53
|
+
if elem.is_a?(Hash)
|
54
|
+
result += flatten_params(elem, "#{calculated_key}[]")
|
55
|
+
elsif elem.is_a?(Array)
|
56
|
+
result += flatten_params_array(elem, calculated_key)
|
57
|
+
else
|
58
|
+
result << ["#{calculated_key}[]", elem]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
result
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/invoiced.rb
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'base64'
|
4
|
+
require 'active_support/inflector'
|
5
|
+
|
6
|
+
require 'invoiced/version'
|
7
|
+
require 'invoiced/util'
|
8
|
+
require 'invoiced/error/error_base'
|
9
|
+
require 'invoiced/error/api_error'
|
10
|
+
require 'invoiced/error/authentication_error'
|
11
|
+
require 'invoiced/error/invalid_request'
|
12
|
+
require 'invoiced/list'
|
13
|
+
require 'invoiced/operations/list'
|
14
|
+
require 'invoiced/operations/create'
|
15
|
+
require 'invoiced/operations/delete'
|
16
|
+
require 'invoiced/operations/update'
|
17
|
+
|
18
|
+
require 'invoiced/object'
|
19
|
+
require 'invoiced/customer'
|
20
|
+
require 'invoiced/invoice'
|
21
|
+
require 'invoiced/transaction'
|
22
|
+
require 'invoiced/plan'
|
23
|
+
require 'invoiced/subscription'
|
24
|
+
|
25
|
+
module Invoiced
|
26
|
+
class Client
|
27
|
+
ApiBase = 'https://api.invoiced.com'
|
28
|
+
|
29
|
+
attr_reader :api_key
|
30
|
+
|
31
|
+
def initialize(api_key)
|
32
|
+
@api_key = api_key
|
33
|
+
end
|
34
|
+
|
35
|
+
def Customer
|
36
|
+
Invoiced::Customer.new(self)
|
37
|
+
end
|
38
|
+
|
39
|
+
def Invoice
|
40
|
+
Invoiced::Invoice.new(self)
|
41
|
+
end
|
42
|
+
|
43
|
+
def Transaction
|
44
|
+
Invoiced::Transaction.new(self)
|
45
|
+
end
|
46
|
+
|
47
|
+
def Plan
|
48
|
+
Invoiced::Plan.new(self)
|
49
|
+
end
|
50
|
+
|
51
|
+
def Subscription
|
52
|
+
Invoiced::Subscription.new(self)
|
53
|
+
end
|
54
|
+
|
55
|
+
def request(method, endpoint, params={})
|
56
|
+
url = ApiBase + endpoint
|
57
|
+
|
58
|
+
case method.to_s.downcase.to_sym
|
59
|
+
# These methods don't have a request body
|
60
|
+
when :get, :head, :delete
|
61
|
+
payload = nil
|
62
|
+
# Otherwise, encode request body to JSON
|
63
|
+
else
|
64
|
+
payload = params.to_json
|
65
|
+
end
|
66
|
+
|
67
|
+
begin
|
68
|
+
response = RestClient::Request.execute(
|
69
|
+
method: method,
|
70
|
+
url: url,
|
71
|
+
headers: {
|
72
|
+
:authorization => Util.auth_header(@api_key),
|
73
|
+
:content_type => "application/json",
|
74
|
+
:user_agent => "Invoiced Ruby/#{Invoiced::VERSION}",
|
75
|
+
# pass in query parameters here due
|
76
|
+
# to an eccentricity in the rest-client gem
|
77
|
+
:params => params.merge({:envelope => '0'})
|
78
|
+
},
|
79
|
+
payload: payload
|
80
|
+
)
|
81
|
+
rescue RestClient::Exception => e
|
82
|
+
if e.response
|
83
|
+
rescue_api_error(e.response)
|
84
|
+
else
|
85
|
+
rescue_rest_client_error(e)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
parse(response)
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def parse(response)
|
95
|
+
unless response.code == 204
|
96
|
+
parsed_response = JSON.parse(response.body, :symbolize_names => true)
|
97
|
+
else
|
98
|
+
parsed_response = nil
|
99
|
+
end
|
100
|
+
|
101
|
+
{
|
102
|
+
:code => response.code,
|
103
|
+
:headers => response.headers,
|
104
|
+
:body => parsed_response
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
def rescue_api_error(response)
|
109
|
+
begin
|
110
|
+
error = JSON.parse(response.body)
|
111
|
+
rescue JSON::ParserError
|
112
|
+
raise general_api_error(response.code, response.body)
|
113
|
+
end
|
114
|
+
|
115
|
+
case response.code
|
116
|
+
when 400, 404
|
117
|
+
raise invalid_request_error(error, response)
|
118
|
+
when 401
|
119
|
+
raise authentication_error(error, response)
|
120
|
+
else
|
121
|
+
raise api_error(error, response)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def rescue_rest_client_error(error)
|
126
|
+
raise ApiError.new("There was an error connecting to Invoiced.")
|
127
|
+
end
|
128
|
+
|
129
|
+
def authentication_error(error, response)
|
130
|
+
raise AuthenticationError.new(error["message"], response.code, error)
|
131
|
+
end
|
132
|
+
|
133
|
+
def invalid_request_error(error, response)
|
134
|
+
raise InvalidRequestError.new(error["message"], response.code, error)
|
135
|
+
end
|
136
|
+
|
137
|
+
def api_error(error, response)
|
138
|
+
raise ApiError.new("Invoiced API Error #{code} - #{body}", response.code, error)
|
139
|
+
end
|
140
|
+
|
141
|
+
def general_api_error(code, body)
|
142
|
+
raise ApiError.new("API Error #{code} - #{body}")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Invoiced
|
4
|
+
class CustomerTest < Test::Unit::TestCase
|
5
|
+
should "create a customer" do
|
6
|
+
customer = @client.Customer.create({:name => "test"})
|
7
|
+
end
|
8
|
+
|
9
|
+
should "list all customers" do
|
10
|
+
@client.Customer.list
|
11
|
+
end
|
12
|
+
|
13
|
+
should "retrieve a customer" do
|
14
|
+
customer = @client.Customer.retrieve(1234)
|
15
|
+
end
|
16
|
+
|
17
|
+
should "update a customer" do
|
18
|
+
customer = Customer.new(@client, 1234)
|
19
|
+
customer.name = 'Update'
|
20
|
+
assert_true(customer.save)
|
21
|
+
end
|
22
|
+
|
23
|
+
should "delete a customer" do
|
24
|
+
customer = Customer.new(@client, 1234)
|
25
|
+
assert_true(customer.delete)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'invoiced'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'mocha/setup'
|
4
|
+
require 'shoulda'
|
5
|
+
|
6
|
+
module Invoiced
|
7
|
+
class InvoicedTest < Test::Unit::TestCase
|
8
|
+
should "create new client" do
|
9
|
+
client = Invoiced::Client.new('api_key')
|
10
|
+
assert_equal('api_key', client.api_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "perform a request" do
|
14
|
+
client = Invoiced::Client.new('api_key')
|
15
|
+
params = {
|
16
|
+
"test" => "property",
|
17
|
+
"filter" => {
|
18
|
+
"levels" => "work"
|
19
|
+
}
|
20
|
+
}
|
21
|
+
client.request("GET", "/invoices", params)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Invoiced
|
4
|
+
class UtilTest < Test::Unit::TestCase
|
5
|
+
should "create an authorization header string" do
|
6
|
+
assert_equal('Basic dGVzdDo=', Util.auth_header("test"))
|
7
|
+
end
|
8
|
+
|
9
|
+
should "build a URI encoded string" do
|
10
|
+
params = {
|
11
|
+
"test" => "property",
|
12
|
+
"filter" => {
|
13
|
+
"levels" => "work"
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
assert_equal("test=property&filter[levels]=work", Util.uri_encode(params))
|
18
|
+
end
|
19
|
+
|
20
|
+
should "create a Customer object" do
|
21
|
+
instance = Invoiced::Customer.new(@client)
|
22
|
+
customer = Util.convert_to_object(instance, {:id => 100})
|
23
|
+
assert_equal('Invoiced::Customer', customer.class.name)
|
24
|
+
assert_equal(100, customer.id)
|
25
|
+
end
|
26
|
+
|
27
|
+
should "create a collection of Customer objects" do
|
28
|
+
instance = Invoiced::Customer.new(@client)
|
29
|
+
objects = [{:id => 100}, {:id => 101}]
|
30
|
+
customers = Util.build_objects(instance, objects)
|
31
|
+
|
32
|
+
assert_equal(2, customers.length)
|
33
|
+
assert_equal(100, customers[0].id)
|
34
|
+
assert_equal(101, customers[1].id)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: invoiced
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jared King
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.8.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.2.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.2.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mocha
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.13.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.13.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: shoulda
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.4.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.4.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: test-unit
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Invoiced makes invoicing and recurring billing dead simple
|
112
|
+
email: api@invoiced.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- .travis.yml
|
119
|
+
- Gemfile
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- invoiced.gemspec
|
123
|
+
- lib/invoiced.rb
|
124
|
+
- lib/invoiced/customer.rb
|
125
|
+
- lib/invoiced/error/api_error.rb
|
126
|
+
- lib/invoiced/error/authentication_error.rb
|
127
|
+
- lib/invoiced/error/error_base.rb
|
128
|
+
- lib/invoiced/error/invalid_request.rb
|
129
|
+
- lib/invoiced/invoice.rb
|
130
|
+
- lib/invoiced/list.rb
|
131
|
+
- lib/invoiced/object.rb
|
132
|
+
- lib/invoiced/operations/create.rb
|
133
|
+
- lib/invoiced/operations/delete.rb
|
134
|
+
- lib/invoiced/operations/list.rb
|
135
|
+
- lib/invoiced/operations/update.rb
|
136
|
+
- lib/invoiced/plan.rb
|
137
|
+
- lib/invoiced/subscription.rb
|
138
|
+
- lib/invoiced/transaction.rb
|
139
|
+
- lib/invoiced/util.rb
|
140
|
+
- lib/invoiced/version.rb
|
141
|
+
- test/invoiced/customer_test.rb
|
142
|
+
- test/invoiced/invoiced_test.rb
|
143
|
+
- test/invoiced/util_test.rb
|
144
|
+
- test/test_helper.rb
|
145
|
+
homepage: https://developers.invoiced.com
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
metadata: {}
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: 1.9.3
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 2.0.14
|
166
|
+
signing_key:
|
167
|
+
specification_version: 4
|
168
|
+
summary: Ruby client library for the Invoiced API
|
169
|
+
test_files:
|
170
|
+
- test/invoiced/customer_test.rb
|
171
|
+
- test/invoiced/invoiced_test.rb
|
172
|
+
- test/invoiced/util_test.rb
|
173
|
+
- test/test_helper.rb
|
174
|
+
has_rdoc:
|