cubaru 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/cubaru.gemspec +29 -0
- data/lib/cubaru.rb +63 -0
- data/lib/cubaru/error.rb +4 -0
- data/lib/cubaru/v1/address/resource.rb +34 -0
- data/lib/cubaru/v1/postcard/resource.rb +39 -0
- data/lib/cubaru/v1/resource.rb +43 -0
- data/lib/cubaru/version.rb +3 -0
- data/spec/cubaru/v1/address/resource_spec.rb +71 -0
- data/spec/cubaru/v1/postcard/resource_spec.rb +129 -0
- data/spec/cubaru/v1/resource_spec.rb +30 -0
- data/spec/cubaru_spec.rb +32 -0
- data/spec/fixtures/back.pdf +0 -0
- data/spec/fixtures/front.pdf +0 -0
- data/spec/spec_helper.rb +13 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4734fd5a4afb64d4a2f8d16d3fa4439ed5ee2115
|
4
|
+
data.tar.gz: bbe25ff4ef35f71f04b741006ddd9f524381389c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1177ce896ccdb36430900901d376df6fe368b3dc988145cfc215477094fc311f4786210431838239d6b2164df6391d13d1170cef89313e976d3909f1be29999f
|
7
|
+
data.tar.gz: 55b09b5a3e7859098ec1ba27e752677de9cb0444c786ade17240bc6fd42f9808e513d442cb593271e14705704b97fd15bbb2ae7ec19d473f5463d6f0a124ca99
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 hitoshi.tsuyuki
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Cubaru::Ruby
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'cubaru'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install cubaru
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/cubaru.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cubaru/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cubaru"
|
8
|
+
spec.version = Cubaru::VERSION
|
9
|
+
spec.authors = ["hitoshi.tsuyuki"]
|
10
|
+
spec.email = ["hitoshi.tsuyuki"]
|
11
|
+
spec.summary = %q{Ruby bindings for the Cubaru API}
|
12
|
+
spec.description = %q{Cubaru is the easiest way to print and mail. See https://www.cubaru.com for details}
|
13
|
+
spec.homepage = "https://www.cubaru.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency('rest-client', '~> 1.6')
|
22
|
+
spec.add_dependency('json', '~> 1.8.1')
|
23
|
+
|
24
|
+
spec.add_development_dependency 'guard'
|
25
|
+
spec.add_development_dependency 'guard-rspec'
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "vcr"
|
28
|
+
spec.add_development_dependency "webmock", '~> 1.15.2'
|
29
|
+
end
|
data/lib/cubaru.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require "cubaru/version"
|
5
|
+
require 'cubaru/error'
|
6
|
+
require 'cubaru/v1/resource'
|
7
|
+
require "cubaru/v1/address/resource"
|
8
|
+
require "cubaru/v1/postcard/resource"
|
9
|
+
|
10
|
+
module Cubaru
|
11
|
+
class << self
|
12
|
+
attr_accessor :api_key,
|
13
|
+
:api_version,
|
14
|
+
:protocol,
|
15
|
+
:api_host
|
16
|
+
|
17
|
+
def configure
|
18
|
+
yield self
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def require_options(options, *keys)
|
23
|
+
keys.each do |key|
|
24
|
+
raise ArgumentError.new(":#{key} is required") unless options.key?(key)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def submit(method, url, parameters={})
|
29
|
+
parameters = {:params => parameters} if method == :get
|
30
|
+
JSON(RestClient.send(method, url, parameters))
|
31
|
+
rescue => e
|
32
|
+
error_message = nil
|
33
|
+
raise e unless e.respond_to? :http_body
|
34
|
+
begin
|
35
|
+
json = JSON(e.http_body)
|
36
|
+
|
37
|
+
if json.has_key? 'errors'
|
38
|
+
error_message = json["errors"].first.values.first
|
39
|
+
elsif json.has_key? 'message'
|
40
|
+
error_message = json["message"]
|
41
|
+
else
|
42
|
+
error_message = "Unknown error: #{json}"
|
43
|
+
end
|
44
|
+
rescue => e
|
45
|
+
raise e
|
46
|
+
end
|
47
|
+
raise Cubaru::Error.new(error_message)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def Cubaru(options={})
|
53
|
+
options[:api_host] ||= Cubaru.api_host || "api.cubaru.com"
|
54
|
+
options[:protocol] ||= Cubaru.protocol || "https"
|
55
|
+
options[:api_version] ||= Cubaru.api_version || "v1"
|
56
|
+
options[:api_key] ||= Cubaru.api_key
|
57
|
+
|
58
|
+
unless options[:api_key]
|
59
|
+
raise ArgumentError.new(":api_key is a required argument to initialize Cubaru")
|
60
|
+
end
|
61
|
+
|
62
|
+
Cubaru.const_get("#{options[:api_version].capitalize}").const_get("Resource").new(options)
|
63
|
+
end
|
data/lib/cubaru/error.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Cubaru
|
2
|
+
module V1
|
3
|
+
module Address
|
4
|
+
class Resource
|
5
|
+
|
6
|
+
def initialize(resource)
|
7
|
+
@resource = resource
|
8
|
+
end
|
9
|
+
|
10
|
+
def list(options={})
|
11
|
+
Cubaru.submit(:get, address_url, options)["data"] || []
|
12
|
+
end
|
13
|
+
|
14
|
+
def find(address_id)
|
15
|
+
Cubaru.submit :get, address_url(address_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(options = {})
|
19
|
+
Cubaru.submit :post, address_url, @resource.format_address_params(options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def destroy(address_id)
|
23
|
+
Cubaru.submit :delete, address_url(address_id)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def address_url(address_id = nil)
|
29
|
+
@resource.construct_url("addresses", address_id)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Cubaru
|
2
|
+
module V1
|
3
|
+
module Postcard
|
4
|
+
class Resource
|
5
|
+
|
6
|
+
def initialize(resource)
|
7
|
+
@resource = resource
|
8
|
+
end
|
9
|
+
|
10
|
+
def list(options={})
|
11
|
+
Cubaru.submit(:get, postcard_url, options)["data"] || []
|
12
|
+
end
|
13
|
+
|
14
|
+
def find(postcard_id)
|
15
|
+
Cubaru.submit :get, postcard_url(postcard_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(options = {})
|
19
|
+
if options[:to] && !options[:to].is_a?(String)
|
20
|
+
options[:to] = @resource.format_address_params(options[:to])
|
21
|
+
end
|
22
|
+
|
23
|
+
if options[:from] && !options[:from].is_a?(String)
|
24
|
+
options[:from] = @resource.format_address_params(options[:from])
|
25
|
+
end
|
26
|
+
|
27
|
+
Cubaru.submit :post, postcard_url, options
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def postcard_url(postcard_id = nil)
|
33
|
+
@resource.construct_url("postcards", postcard_id)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Cubaru
|
2
|
+
module V1
|
3
|
+
class Resource
|
4
|
+
|
5
|
+
attr_accessor :options
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def addresses
|
12
|
+
Cubaru::V1::Address::Resource.new(self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def postcards
|
16
|
+
Cubaru::V1::Postcard::Resource.new(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def base_url
|
20
|
+
"#{@options[:protocol]}://#{@options[:api_key]}:@#{@options[:api_host]}/v1"
|
21
|
+
end
|
22
|
+
|
23
|
+
def construct_url(resource_type, resource_id=nil)
|
24
|
+
"#{base_url}/#{resource_type}#{'/' + resource_id if resource_id}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def format_address_params(params, check_required_options=true)
|
28
|
+
if check_required_options
|
29
|
+
Cubaru.require_options(params, :name, :address_line1, :city, :state, :zip, :country)
|
30
|
+
end
|
31
|
+
|
32
|
+
new_params = params.clone
|
33
|
+
|
34
|
+
[:city, :state, :zip, :country].each do |option|
|
35
|
+
new_params["address_#{option}".to_sym] = params[option] if params[option]
|
36
|
+
new_params.delete(option)
|
37
|
+
end
|
38
|
+
|
39
|
+
new_params
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Cubaru::V1::Address::Resource do
|
4
|
+
let(:sample_params2) {
|
5
|
+
{
|
6
|
+
name: "Test1",
|
7
|
+
email: "test@test.com",
|
8
|
+
address_line1: "テスト区テスト町1−2",
|
9
|
+
city: "横浜市",
|
10
|
+
state: "神奈川",
|
11
|
+
country: "JP",
|
12
|
+
zip: "2220002"
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
let(:sample_params) {
|
17
|
+
{
|
18
|
+
name: "Test",
|
19
|
+
email: "test@test.com",
|
20
|
+
address_line1: "テスト町1−1",
|
21
|
+
city: "港区",
|
22
|
+
state: "東京都",
|
23
|
+
country: "JP",
|
24
|
+
zip: "108-0000"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
subject { Cubaru(api_key: ENV["CUBARU_API_KEY"], api_version: "v1") }
|
29
|
+
|
30
|
+
describe "list" do
|
31
|
+
it "should list addresses" do
|
32
|
+
VCR.use_cassette('list_addresses') do
|
33
|
+
new_address = subject.addresses.create sample_params
|
34
|
+
list_result = subject.addresses.list
|
35
|
+
expect(list_result.to_s).to match(/#{new_address["name"]}/)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
describe "create" do
|
42
|
+
it "should create an address" do
|
43
|
+
VCR.use_cassette('create_address') do
|
44
|
+
result = subject.addresses.create sample_params
|
45
|
+
expect(sample_params[:name].to_s).to match(/#{result["name"]}/)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
describe "find" do
|
52
|
+
it "should find an address" do
|
53
|
+
VCR.use_cassette('find_address') do
|
54
|
+
new_address = subject.addresses.create sample_params
|
55
|
+
|
56
|
+
find_result = subject.addresses.find(new_address["id"])
|
57
|
+
expect(find_result['name']).to match(/#{sample_params[:name]}/)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
describe "destroy" do
|
64
|
+
it "should delete an address" do
|
65
|
+
VCR.use_cassette('delete_address') do
|
66
|
+
new_address = subject.addresses.create sample_params
|
67
|
+
expect { subject.addresses.destroy(new_address["id"]) }.not_to raise_error
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Cubaru::V1::Postcard::Resource do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@sample_address_params = {
|
7
|
+
name: "Test1",
|
8
|
+
email: "test@test.com",
|
9
|
+
address_line1: "テスト区テスト町1−2",
|
10
|
+
address_line2: "テストハイツ201",
|
11
|
+
city: "横浜市",
|
12
|
+
state: "神奈川",
|
13
|
+
country: "JP",
|
14
|
+
zip: "2220002"
|
15
|
+
}
|
16
|
+
|
17
|
+
@sample_postcard_params = {
|
18
|
+
name: "TestPostcard",
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
subject { Cubaru(api_key: ENV["CUBARU_API_KEY"], api_version: "v1") }
|
23
|
+
|
24
|
+
describe "create" do
|
25
|
+
it "should create a postcard with address_id" do
|
26
|
+
VCR.use_cassette('create_postcard_with_address_id') do
|
27
|
+
new_address = subject.addresses.create @sample_address_params
|
28
|
+
|
29
|
+
result = subject.postcards.create(
|
30
|
+
name: @sample_postcard_params[:name],
|
31
|
+
to: new_address["id"],
|
32
|
+
from: @sample_address_params,
|
33
|
+
back: "https://www.cubaru.com/back.pdf"
|
34
|
+
)
|
35
|
+
|
36
|
+
expect(result["name"]).to eq(@sample_postcard_params[:name])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
it "should create a postcard with address params" do
|
42
|
+
VCR.use_cassette('create_postcard_with_address_params') do
|
43
|
+
|
44
|
+
result = subject.postcards.create(
|
45
|
+
name: @sample_postcard_params[:name],
|
46
|
+
to: @sample_address_params,
|
47
|
+
from: @sample_address_params,
|
48
|
+
back: "https://www.cubaru.com/back.pdf"
|
49
|
+
)
|
50
|
+
|
51
|
+
expect(result["name"]).to eq(@sample_postcard_params[:name])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
it "should create a postcard with front and back as urls" do
|
57
|
+
VCR.use_cassette('create_postcard_with_front_and_back_urls') do
|
58
|
+
new_address = subject.addresses.create @sample_address_params
|
59
|
+
|
60
|
+
result = subject.postcards.create(
|
61
|
+
name: @sample_postcard_params[:name],
|
62
|
+
to: new_address["id"],
|
63
|
+
from: @sample_address_params,
|
64
|
+
front: "https://www.cubaru.com/front.pdf",
|
65
|
+
back: "https://www.cubaru.com/back.pdf"
|
66
|
+
)
|
67
|
+
|
68
|
+
expect(result["name"]).to eq(@sample_postcard_params[:name])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should create a postcard with front and back as PDFs" do
|
73
|
+
VCR.use_cassette('create_postcard_with_front_and_back_pdfs') do
|
74
|
+
new_address = subject.addresses.create @sample_address_params
|
75
|
+
|
76
|
+
result = subject.postcards.create(
|
77
|
+
name: @sample_postcard_params[:name],
|
78
|
+
to: new_address["id"],
|
79
|
+
from: @sample_address_params,
|
80
|
+
front: fixture_file('front.pdf'),
|
81
|
+
back: fixture_file('back.pdf')
|
82
|
+
)
|
83
|
+
|
84
|
+
expect(result["name"]).to eq @sample_postcard_params[:name]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
describe "find" do
|
92
|
+
it "should find a postcard" do
|
93
|
+
VCR.use_cassette('find_postcard') do
|
94
|
+
new_address = subject.addresses.create @sample_address_params
|
95
|
+
|
96
|
+
new_postcard = subject.postcards.create(
|
97
|
+
name: @sample_postcard_params[:name],
|
98
|
+
to: new_address["id"],
|
99
|
+
from: @sample_address_params,
|
100
|
+
front: fixture_file('front.pdf'),
|
101
|
+
back: fixture_file('back.pdf')
|
102
|
+
)
|
103
|
+
|
104
|
+
result = subject.postcards.find(new_postcard["id"])
|
105
|
+
expect(result["name"]).to eq(@sample_postcard_params[:name])
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "list" do
|
111
|
+
it "should list postcards" do
|
112
|
+
VCR.use_cassette('list_postcards') do
|
113
|
+
new_address = subject.addresses.create @sample_address_params
|
114
|
+
|
115
|
+
new_postcard = subject.postcards.create(
|
116
|
+
name: @sample_postcard_params[:name],
|
117
|
+
to: new_address["id"],
|
118
|
+
from: @sample_address_params,
|
119
|
+
front: fixture_file('front.pdf'),
|
120
|
+
back: fixture_file('back.pdf')
|
121
|
+
)
|
122
|
+
|
123
|
+
list_result = subject.postcards.list
|
124
|
+
expect(list_result.to_s).to match /#{new_postcard["name"]}/
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Cubaru::V1::Resource do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@api_key = "test"
|
7
|
+
end
|
8
|
+
|
9
|
+
subject(:resource) { Cubaru(api_key: @api_key) }
|
10
|
+
|
11
|
+
describe "when Cubaru is initialized" do
|
12
|
+
it "should receive and contain default options when Cubaru is initialized" do
|
13
|
+
expect(resource.options[:protocol]).to eq "https"
|
14
|
+
expect(resource.options[:api_host]).to eq "api.cubaru.com"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have API key in options" do
|
18
|
+
expect(resource.options[:api_key]).to eq @api_key
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return addresses resource" do
|
23
|
+
expect(resource.addresses).to be_kind_of(Cubaru::V1::Address::Resource)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return postcards resource" do
|
27
|
+
expect(resource.postcards).to be_kind_of(Cubaru::V1::Postcard::Resource)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/spec/cubaru_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Cubaru
|
4
|
+
module Test
|
5
|
+
class Resource
|
6
|
+
attr_accessor :options
|
7
|
+
def initialize(options)
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Cubaru do
|
15
|
+
it "should return the resource object for the specified version" do
|
16
|
+
expect(Cubaru(api_key: "test", api_version: "test")).to be_kind_of(Cubaru::Test::Resource)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should raise an error if API key is not passed as an option or set on module" do
|
20
|
+
Cubaru.api_key = nil # make sure API key is nil
|
21
|
+
expect{ Cubaru() }.to raise_error(ArgumentError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should *not* raise an error if API key has been on module and not passed as option" do
|
25
|
+
Cubaru.api_key = "test"
|
26
|
+
expect(Cubaru()).not_to be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should pass the API key to the resource for the version" do
|
30
|
+
expect(Cubaru(api_key: "test").options[:api_key]).to eq "test"
|
31
|
+
end
|
32
|
+
end
|
Binary file
|
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$:.unshift File.expand_path("../lib", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require "cubaru"
|
4
|
+
require "vcr"
|
5
|
+
|
6
|
+
VCR.configure do |config|
|
7
|
+
config.cassette_library_dir = "spec/cassettes"
|
8
|
+
config.hook_into :webmock
|
9
|
+
end
|
10
|
+
|
11
|
+
def fixture_file(filename)
|
12
|
+
File.new(File.expand_path("../fixtures/front.pdf", __FILE__))
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cubaru
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hitoshi.tsuyuki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-03 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.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
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.1
|
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.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
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: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.15.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.15.2
|
111
|
+
description: Cubaru is the easiest way to print and mail. See https://www.cubaru.com
|
112
|
+
for details
|
113
|
+
email:
|
114
|
+
- hitoshi.tsuyuki
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- Gemfile
|
121
|
+
- Guardfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- cubaru.gemspec
|
126
|
+
- lib/cubaru.rb
|
127
|
+
- lib/cubaru/error.rb
|
128
|
+
- lib/cubaru/v1/address/resource.rb
|
129
|
+
- lib/cubaru/v1/postcard/resource.rb
|
130
|
+
- lib/cubaru/v1/resource.rb
|
131
|
+
- lib/cubaru/version.rb
|
132
|
+
- spec/cubaru/v1/address/resource_spec.rb
|
133
|
+
- spec/cubaru/v1/postcard/resource_spec.rb
|
134
|
+
- spec/cubaru/v1/resource_spec.rb
|
135
|
+
- spec/cubaru_spec.rb
|
136
|
+
- spec/fixtures/back.pdf
|
137
|
+
- spec/fixtures/front.pdf
|
138
|
+
- spec/spec_helper.rb
|
139
|
+
homepage: https://www.cubaru.com
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.0.14
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Ruby bindings for the Cubaru API
|
163
|
+
test_files:
|
164
|
+
- spec/cubaru/v1/address/resource_spec.rb
|
165
|
+
- spec/cubaru/v1/postcard/resource_spec.rb
|
166
|
+
- spec/cubaru/v1/resource_spec.rb
|
167
|
+
- spec/cubaru_spec.rb
|
168
|
+
- spec/fixtures/back.pdf
|
169
|
+
- spec/fixtures/front.pdf
|
170
|
+
- spec/spec_helper.rb
|
171
|
+
has_rdoc:
|