zaim 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a4fc74f1da0c173982df1c10b309dedce625fd77
4
+ data.tar.gz: cacb67f75116313c444ec158e91695526e6132ea
5
+ SHA512:
6
+ metadata.gz: 8135f08c20ae7bfbc652b33d028c305d90b6b75c9079e74d41666ea065176d6b998b065e6a594cfe7638e01a1a3a51a8e277f6048a205128c281c0799b125f71
7
+ data.tar.gz: 84524543e4ef974a2a41202d75a29f7f5c7c271f3ab1af5e784b6568e8d3ed73ed1019700e359413b7952104503f4afde5da3d5768e081d0af4ae10b8aa29744
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zaim.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 toshiwo
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.
@@ -0,0 +1,45 @@
1
+ # Zaim
2
+
3
+ A Ruby wrapper for the Zaim API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'zaim'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install zaim
18
+
19
+ ## Usage
20
+
21
+ ### Setup
22
+
23
+ ```ruby
24
+ Zaim.configure do |config|
25
+ config.consumer_key = YOUR_CONSUMER_KEY
26
+ config.consumer_secret = OUR_CONSUMER_SECRET
27
+ config.oauth_token = YOUR_OAUTH_TOKEN
28
+ config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
29
+ end
30
+ ```
31
+
32
+ ```ruby
33
+ client = Zaim::Client.new
34
+
35
+ client.verify
36
+ {"me"=>{"login"=>"....."}, "requested"=>1370894199}
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ Dir['tasks/**/*.rake'].each { |t| load t }
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
@@ -0,0 +1,11 @@
1
+ require "zaim/version"
2
+ require 'zaim/configuration'
3
+ require 'zaim/client'
4
+
5
+ module Zaim
6
+
7
+ class << self
8
+ include Zaim::Configuration
9
+ end
10
+
11
+ end
@@ -0,0 +1,9 @@
1
+ module Zaim
2
+ module Account
3
+
4
+ def account params = {}
5
+ get('/v2/home/account', params)
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Zaim
2
+ module Category
3
+
4
+ def category params = {}
5
+ get('/v2/home/category', params)
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ require 'zaim/request'
2
+ require 'zaim/user'
3
+ require 'zaim/money'
4
+ require 'zaim/category'
5
+ require 'zaim/genre'
6
+ require 'zaim/account'
7
+
8
+ module Zaim
9
+ class Client
10
+ include Zaim::Configuration
11
+ include Zaim::Request
12
+ include Zaim::User
13
+ include Zaim::Money
14
+ include Zaim::Category
15
+ include Zaim::Genre
16
+ include Zaim::Account
17
+
18
+ def initialize options = {}
19
+ OptionKeys.each do |attr_name|
20
+ instance_variable_set(:"@#{ attr_name }", options[attr_name] || Zaim.instance_variable_get(:"@#{ attr_name }"))
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module Zaim
2
+ module Configuration
3
+
4
+ OptionKeys = [ :consumer_key, :consumer_secret, :oauth_token, :oauth_token_secret ]
5
+
6
+ attr_writer :consumer_secret, :oauth_token, :oauth_token_secret
7
+ attr_accessor :consumer_key
8
+
9
+ def configure
10
+ yield self
11
+ self
12
+ end
13
+
14
+ def credentials
15
+ {
16
+ :consumer_key => @consumer_key,
17
+ :consumer_secret => @consumer_secret,
18
+ :token => @oauth_token,
19
+ :token_secret => @oauth_token_secret,
20
+ }
21
+ end
22
+ private :credentials
23
+
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ module Zaim
2
+ module Genre
3
+
4
+ def genre params = {}
5
+ get('/v2/home/genre', params)
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,42 @@
1
+ module Zaim
2
+ module Money
3
+
4
+ def money params = {}
5
+ get('/v2/home/money', params)
6
+ end
7
+
8
+ def payment params
9
+ post('/v2/home/money/payment', params)
10
+ end
11
+
12
+ def income params
13
+ post('/v2/home/money/income', params)
14
+ end
15
+
16
+ def transfer params
17
+ post('/v2/home/money/transfer', params)
18
+ end
19
+
20
+ def update type, id, params = {}
21
+ unless check_resource_type type
22
+ raise ArgumentError, "unkown type argument of '#{ type }'"
23
+ end
24
+
25
+ put("/v2/home/money/#{ type }/#{ id }", params)
26
+ end
27
+
28
+ def delete type, id #, params = {} # TODO:
29
+ unless check_resource_type type
30
+ raise ArgumentError, "unkown type argument of '#{ type }'"
31
+ end
32
+
33
+ request(:delete, "/v2/home/money/#{ type }/#{ id }")
34
+ end
35
+
36
+ def check_resource_type type
37
+ %w( payment income transfer ).include? type.to_s
38
+ end
39
+ private :check_resource_type
40
+
41
+ end
42
+ end
@@ -0,0 +1,53 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ module Zaim
5
+ module Request
6
+
7
+ def get(path, params = {})
8
+ request(:get, path, params)
9
+ end
10
+ private :get
11
+
12
+ def post(path, params = {})
13
+ request(:post, path, params)
14
+ end
15
+ private :post
16
+
17
+ def put(path, params = {})
18
+ request(:put, path, params)
19
+ end
20
+ private :put
21
+
22
+ def request(method, path, params = {})
23
+ response = connection.send(method) do |request|
24
+ case method
25
+ when :get, :delete
26
+ request.url(path, params)
27
+ when :post, :put
28
+ request.path = path
29
+ request.body = params unless params.empty?
30
+ end
31
+ end
32
+
33
+ response.body
34
+ end
35
+ private :request
36
+
37
+ def connection
38
+ options = {
39
+ :url => 'https://api.zaim.net',
40
+ }
41
+
42
+ Faraday.new(options) do |connection|
43
+ connection.response :raise_error
44
+ connection.response :json, :content_type => /\bjson$/
45
+ connection.request :oauth, credentials
46
+ connection.request :url_encoded
47
+ connection.adapter Faraday.default_adapter
48
+ end
49
+ end
50
+ private :connection
51
+
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ module Zaim
2
+ module User
3
+
4
+ def verify
5
+ get('/v2/home/user/verify')
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Zaim
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,17 @@
1
+ {
2
+ "accounts": [
3
+ {
4
+ "id": 1,
5
+ "name": "Wallet",
6
+ "color": "#80502C",
7
+ "icon_url": "https://www.zaim.net/images/icons/cash/wallet.png"
8
+ },
9
+ {
10
+ "id": 2,
11
+ "name": "Savings",
12
+ "color": "#80502C",
13
+ "icon_url": "https://www.zaim.net/images/icons/cash/saving.png"
14
+ }
15
+ ],
16
+ "requested": 1321795444
17
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "categories": [
3
+ {
4
+ "id": 12093,
5
+ "name": "Food",
6
+ "mode": "payment",
7
+ "sort": 1,
8
+ "parent_category_id": 101
9
+ },
10
+ {
11
+ "id": 12094,
12
+ "name": "Daily good",
13
+ "mode": "payment",
14
+ "sort": 2,
15
+ "parent_category_id": 102
16
+ }
17
+ ],
18
+ "requested": 1321795825
19
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "genres": [
3
+ {
4
+ "id": 12093,
5
+ "name": "Food",
6
+ "mode": "payment",
7
+ "sort": 1,
8
+ "parent_genre_id": 101
9
+ },
10
+ {
11
+ "id": 12094,
12
+ "name": "Daily good",
13
+ "mode": "payment",
14
+ "sort": 2,
15
+ "parent_genre_id": 102
16
+ }
17
+ ],
18
+ "requested": 1321795825
19
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "money": [
3
+ {
4
+ "id": 381, // unique input id
5
+ "type": "income", // income or pay
6
+ "user_id": 1,
7
+ "date": "2011-11-07",
8
+ "category_id": 11,
9
+ "genre_id": 0,
10
+ "to_account_id": 34555,
11
+ "from_account_id": 0,
12
+ "amount": 10000,
13
+ "comment": "",
14
+ "place": "",
15
+ "created": "2011-11-07 01:10:50",
16
+ "currency_code": "JPY"
17
+ },
18
+ {
19
+ "id": 382,
20
+ "type": "payment",
21
+ "user_id": 1,
22
+ "date": "2011-11-07",
23
+ "category_id": 101,
24
+ "genre_id": 10101,
25
+ "genre_id": 0,
26
+ "from_account_id": 34555,
27
+ "to_account_id": 0,
28
+ "comment": "",
29
+ "place": "",
30
+ "amount": 100,
31
+ "created": "2011-11-07 01:12:00",
32
+ "currency_code": "JPY"
33
+ }
34
+ ],
35
+ "requested": 1321782829
36
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "stamps": {
3
+ "kiriban": {
4
+ "image_url": "http://f.zaim.net/seal/cup.png",
5
+ "name": "Get a milestone stamp!",
6
+ "description": "Just wrote 100 times."
7
+ },
8
+ "repeat": {
9
+ "image_url": "http://f.zaim.net/seal/cup.png",
10
+ "name": "Get the ongoing stamp!",
11
+ "description": "10 consecutive days."
12
+ },
13
+ "first": {
14
+ "image_url": "http://f.zaim.net/seal/cup.png",
15
+ "name": "Get the first stamp!",
16
+ "description": "Wrote for the first time today."
17
+ }
18
+ },
19
+ "money": {
20
+ "id": 11002,
21
+ "modified": "2011-11-07 01:23:45"
22
+ },
23
+ "user": {
24
+ "input_count": 12,
25
+ "repeat_count": 1,
26
+ "day_count": 10
27
+ },
28
+ "requested": "1305217527"
29
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "stamps": {
3
+ "kiriban": {
4
+ "image_url": "http://f.zaim.net/seal/cup.png",
5
+ "name": "Get a milestone stamp!",
6
+ "description": "Just wrote 100 times."
7
+ },
8
+ "repeat": {
9
+ "image_url": "http://f.zaim.net/seal/cup.png",
10
+ "name": "Get the ongoing stamp!",
11
+ "description": "10 consecutive days."
12
+ },
13
+ "first": {
14
+ "image_url": "http://f.zaim.net/seal/cup.png",
15
+ "name": "Get the first stamp!",
16
+ "description": "Wrote for the first time today."
17
+ }
18
+ },
19
+ "money": {
20
+ "id": 10002,
21
+ "modified": "2011-11-07 01:23:45"
22
+ },
23
+ "user": {
24
+ "input_count": 12,
25
+ "repeat_count": 1,
26
+ "day_count": 10
27
+ },
28
+ "requested": "1305217527"
29
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "stamps": {
3
+ "kiriban": {
4
+ "image_url": "http://f.zaim.net/seal/cup.png",
5
+ "name": "Get a milestone stamp!",
6
+ "description": "Just wrote 100 times."
7
+ },
8
+ "repeat": {
9
+ "image_url": "http://f.zaim.net/seal/cup.png",
10
+ "name": "Get the ongoing stamp!",
11
+ "description": "10 consecutive days."
12
+ },
13
+ "first": {
14
+ "image_url": "http://f.zaim.net/seal/cup.png",
15
+ "name": "Get the first stamp!",
16
+ "description": "Wrote for the first time today."
17
+ }
18
+ },
19
+ "money": {
20
+ "id": 12002,
21
+ "modified": "2011-11-07 01:23:45"
22
+ },
23
+ "user": {
24
+ "input_count": 12,
25
+ "repeat_count": 1,
26
+ "day_count": 10
27
+ },
28
+ "requested": "1305217527"
29
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "me": {
3
+ "id": 10000000, // unique user id
4
+ "login": "XXXXXXX", // unique string for user login
5
+ "name": "MyName", // user name
6
+ "input_count": 100, // total number of inputs
7
+ "day_count": 10, // total number of days
8
+ "repeat_count": 2, // days continuous recording
9
+ "day": 1, // start date of the month
10
+ "week": 3, // first day of the week
11
+ "month": 7, // start date of the year
12
+ "currency_code": "JPY" // default currency code
13
+ },
14
+ "requested": 1367902710
15
+ }
@@ -0,0 +1,26 @@
1
+ require 'webmock/rspec'
2
+
3
+ if ENV['COVERAGE']
4
+ require "simplecov"
5
+
6
+ SimpleCov.start :test_frameworks do
7
+ add_filter "/vendor/bundle/"
8
+ end
9
+ end
10
+
11
+ require 'zaim'
12
+
13
+ # Requires supporting ruby files with custom matchers and macros, etc,
14
+ # in spec/support/ and its subdirectories.
15
+ Dir[File.expand_path("./support/**/*.rb", File.dirname(__FILE__))].each {|f| require f}
16
+
17
+ RSpec.configure do |config|
18
+ # == Mock Framework
19
+ #
20
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
21
+ #
22
+ # config.mock_with :mocha
23
+ # config.mock_with :flexmock
24
+ # config.mock_with :rr
25
+ # config.mock_with :rspec
26
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zaim::Account do
4
+
5
+ let(:request_url) { 'https://api.zaim.net/v2/home/account' }
6
+ let(:response_headers) { { content_type: 'application/json' } }
7
+ let(:response_body) { File.read('spec/fixtures/account.json') }
8
+ let(:response) { { body: response_body, status: 200, headers: response_headers } }
9
+ let(:client) { Zaim::Client.new }
10
+
11
+ describe "#account" do
12
+
13
+ before do
14
+ stub_request( :get, request_url ).to_return( response )
15
+ end
16
+
17
+ subject { client.account }
18
+
19
+ it { expect( subject ).to be_an_instance_of Hash }
20
+ it { expect( subject ).to include('requested') }
21
+ it { expect( subject ).to include('accounts') }
22
+
23
+ context "response 'accounts'" do
24
+
25
+ subject { client.account.fetch 'accounts' }
26
+
27
+ it { expect( subject ).to be_an_instance_of Array }
28
+
29
+ %w( id name color icon_url ).each do |key_name|
30
+ it { expect( subject.first ).to include(key_name) }
31
+ end
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zaim::Category do
4
+
5
+ let(:request_url) { 'https://api.zaim.net/v2/home/category' }
6
+ let(:response_headers) { { content_type: 'application/json' } }
7
+ let(:response_body) { File.read('spec/fixtures/category.json') }
8
+ let(:response) { { body: response_body, status: 200, headers: response_headers } }
9
+ let(:client) { Zaim::Client.new }
10
+
11
+ describe "#category" do
12
+
13
+ before do
14
+ stub_request( :get, request_url ).to_return( response )
15
+ end
16
+
17
+ subject { client.category }
18
+
19
+ it { expect( subject ).to be_an_instance_of Hash }
20
+ it { expect( subject ).to include('requested') }
21
+ it { expect( subject ).to include('categories') }
22
+
23
+ context "response 'categories'" do
24
+
25
+ subject { client.category.fetch 'categories' }
26
+
27
+ it { expect( subject ).to be_an_instance_of Array }
28
+
29
+ %w( id name mode sort parent_category_id ).each do |key_name|
30
+ it { expect( subject.first ).to include(key_name) }
31
+ end
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zaim::Client do
4
+
5
+ subject { Zaim::Client.new }
6
+
7
+ it { expect( subject ).to be_an_instance_of Zaim::Client }
8
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zaim::Genre do
4
+
5
+ let(:request_url) { 'https://api.zaim.net/v2/home/genre' }
6
+ let(:response_headers) { { content_type: 'application/json' } }
7
+ let(:response_body) { File.read('spec/fixtures/genre.json') }
8
+ let(:response) { { body: response_body, status: 200, headers: response_headers } }
9
+ let(:client) { Zaim::Client.new }
10
+
11
+ describe "#genre" do
12
+
13
+ before do
14
+ stub_request( :get, request_url ).to_return( response )
15
+ end
16
+
17
+ subject { client.genre }
18
+
19
+ it { expect( subject ).to be_an_instance_of Hash }
20
+ it { expect( subject ).to include('requested') }
21
+ it { expect( subject ).to include('genres') }
22
+
23
+ context "response 'genres'" do
24
+
25
+ subject { client.genre.fetch 'genres' }
26
+
27
+ it { expect( subject ).to be_an_instance_of Array }
28
+
29
+ %w( id name mode sort parent_genre_id ).each do |key_name|
30
+ it { expect( subject.first ).to include(key_name) }
31
+ end
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zaim::Money do
4
+
5
+ let(:response_headers) { { content_type: 'application/json' } }
6
+ let(:response) { { body: response_body, status: 200, headers: response_headers } }
7
+ let(:client) { Zaim::Client.new }
8
+
9
+ describe "#delete" do
10
+
11
+ before do
12
+ stub_request( :delete, request_url ).to_return( response )
13
+ end
14
+
15
+ context :unknown_type do
16
+
17
+ let(:resource_id) { 10000 }
18
+ let(:request_url) { 'http://example.com/' }
19
+ let(:response_body) { }
20
+
21
+ subject { client.delete :unknown_type, resource_id }
22
+
23
+ it { expect { subject }.to raise_error(ArgumentError) }
24
+ end
25
+
26
+ context :payment do
27
+
28
+ let(:resource_id) { 10002 }
29
+ let(:request_url) { "https://api.zaim.net/v2/home/money/payment/#{ resource_id }" }
30
+ let(:response_body) { File.read('spec/fixtures/money/payment.json') }
31
+
32
+ subject { client.delete :payment, resource_id }
33
+
34
+ it { expect( subject ).to be_an_instance_of Hash }
35
+ it { expect( subject ).to include('requested') }
36
+ it { expect( subject ).to include('money') }
37
+ it { expect( subject ).to include('user') }
38
+ end
39
+
40
+ context :income do
41
+
42
+ let(:resource_id) { 11002 }
43
+ let(:request_url) { "https://api.zaim.net/v2/home/money/income/#{ resource_id }" }
44
+ let(:response_body) { File.read('spec/fixtures/money/income.json') }
45
+
46
+ subject { client.delete :income, resource_id }
47
+
48
+ it { expect( subject ).to be_an_instance_of Hash }
49
+ it { expect( subject ).to include('requested') }
50
+ it { expect( subject ).to include('money') }
51
+ it { expect( subject ).to include('user') }
52
+ end
53
+
54
+ context :transfer do
55
+
56
+ let(:resource_id) { 12002 }
57
+ let(:request_url) { "https://api.zaim.net/v2/home/money/transfer/#{ resource_id }" }
58
+ let(:response_body) { File.read('spec/fixtures/money/transfer.json') }
59
+
60
+ subject { client.delete :transfer, resource_id }
61
+
62
+ it { expect( subject ).to be_an_instance_of Hash }
63
+ it { expect( subject ).to include('requested') }
64
+ it { expect( subject ).to include('money') }
65
+ it { expect( subject ).to include('user') }
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zaim::Money do
4
+
5
+ let(:resource_id) { 10002 }
6
+ let(:response_headers) { { content_type: 'application/json' } }
7
+ let(:response) { { body: response_body, status: 200, headers: response_headers } }
8
+ let(:client) { Zaim::Client.new }
9
+
10
+ describe "#update" do
11
+
12
+ before do
13
+ stub_request( :put, request_url ).to_return( response )
14
+ end
15
+
16
+ context :unknown_type do
17
+
18
+ let(:resource_id) { 10000 }
19
+ let(:request_url) { "http://example.com" }
20
+ let(:response_body) { }
21
+
22
+ let(:params) { { } }
23
+
24
+ subject { client.update :unknown_type, resource_id, params }
25
+
26
+ it { expect { subject }.to raise_error ArgumentError }
27
+ end
28
+
29
+ context :payment do
30
+
31
+ let(:resource_id) { 10002 }
32
+ let(:request_url) { "https://api.zaim.net/v2/home/money/payment/#{ resource_id }" }
33
+ let(:response_body) { File.read('spec/fixtures/money/payment.json') }
34
+
35
+ let(:params) { {
36
+ amount: 2000,
37
+ date: Time.now.strftime('%Y-%m-%d %H:%M:%S'),
38
+ } }
39
+
40
+ subject { client.update :payment, resource_id, params }
41
+
42
+ it { expect( subject ).to be_an_instance_of Hash }
43
+ it { expect( subject ).to include('requested') }
44
+ it { expect( subject ).to include('money') }
45
+ it { expect( subject ).to include('user') }
46
+ end
47
+
48
+ context :income do
49
+
50
+ let(:resource_id) { 11002 }
51
+ let(:request_url) { "https://api.zaim.net/v2/home/money/income/#{ resource_id }" }
52
+ let(:response_body) { File.read('spec/fixtures/money/payment.json') }
53
+
54
+ let(:params) { {
55
+ amount: 10000,
56
+ date: Time.now.strftime('%Y-%m-%d %H:%M:%S'),
57
+ } }
58
+
59
+ subject { client.update :income, resource_id, params }
60
+
61
+ it { expect( subject ).to be_an_instance_of Hash }
62
+ it { expect( subject ).to include('requested') }
63
+ it { expect( subject ).to include('money') }
64
+ it { expect( subject ).to include('user') }
65
+ end
66
+
67
+ context :transfer do
68
+
69
+ let(:resource_id) { 12002 }
70
+ let(:request_url) { "https://api.zaim.net/v2/home/money/transfer/#{ resource_id }" }
71
+ let(:response_body) { File.read('spec/fixtures/money/transfer.json') }
72
+
73
+ subject { client.update :transfer, resource_id }
74
+
75
+ it { expect( subject ).to be_an_instance_of Hash }
76
+ it { expect( subject ).to include('requested') }
77
+ it { expect( subject ).to include('money') }
78
+ it { expect( subject ).to include('user') }
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zaim::Money do
4
+
5
+ let(:response_headers) { { content_type: 'application/json' } }
6
+ let(:response) { { body: response_body, status: 200, headers: response_headers } }
7
+ let(:client) { Zaim::Client.new }
8
+
9
+ describe "#money" do
10
+
11
+ let(:request_url) { 'https://api.zaim.net/v2/home/money' }
12
+ let(:response_body) { File.read('spec/fixtures/money.json') }
13
+
14
+ before do
15
+ stub_request( :get, request_url ).to_return( response )
16
+ end
17
+
18
+ subject { client.money }
19
+
20
+ it { expect( subject ).to be_an_instance_of Hash }
21
+ it { expect( subject ).to include('requested') }
22
+ it { expect( subject ).to include('money') }
23
+
24
+ context "response 'money'" do
25
+
26
+ subject { client.money.fetch 'money' }
27
+
28
+ it { expect( subject ).to be_an_instance_of Array }
29
+
30
+ %w( id type user_id date category_id genre_id to_account_id from_account_id amount comment place created currency_code ).each do |key_name|
31
+ it { expect( subject.first ).to include(key_name) }
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#payment" do
37
+
38
+ let(:request_url) { 'https://api.zaim.net/v2/home/money/payment' }
39
+ let(:response_body) { File.read('spec/fixtures/money/payment.json') }
40
+
41
+ let(:params) { {
42
+ category_id: 100,
43
+ genre_id: 100,
44
+ amount: 1000,
45
+ date: "2011-11-07 01:23:45"
46
+ } }
47
+
48
+ before do
49
+ stub_request( :post, request_url ).to_return( response )
50
+ end
51
+
52
+ subject { client.payment params }
53
+
54
+ it { expect( subject ).to be_an_instance_of Hash }
55
+ it { expect( subject ).to include('requested') }
56
+ it { expect( subject ).to include('money') }
57
+ it { expect( subject ).to include('user') }
58
+ end
59
+
60
+ describe "#income" do
61
+
62
+ let(:request_url) { 'https://api.zaim.net/v2/home/money/income' }
63
+ let(:response_body) { File.read('spec/fixtures/money/income.json') }
64
+
65
+ let(:params) { {
66
+ category_id: 100,
67
+ amount: 1000,
68
+ date: "2011-11-07 01:23:45"
69
+ } }
70
+
71
+ before do
72
+ stub_request( :post, request_url ).to_return( response )
73
+ end
74
+
75
+ subject { client.income params }
76
+
77
+ it { expect( subject ).to be_an_instance_of Hash }
78
+ it { expect( subject ).to include('requested') }
79
+ it { expect( subject ).to include('money') }
80
+ it { expect( subject ).to include('user') }
81
+ end
82
+
83
+ describe "#transfer" do
84
+
85
+ let(:request_url) { 'https://api.zaim.net/v2/home/money/transfer' }
86
+ let(:response_body) { File.read('spec/fixtures/money/transfer.json') }
87
+
88
+ let(:params) { {
89
+ category_id: 100,
90
+ amount: 1000,
91
+ date: "2011-11-07 01:23:45"
92
+ } }
93
+
94
+ before do
95
+ stub_request( :post, request_url ).to_return( response )
96
+ end
97
+
98
+ subject { client.transfer params }
99
+
100
+ it { expect( subject ).to be_an_instance_of Hash }
101
+ it { expect( subject ).to include('requested') }
102
+ it { expect( subject ).to include('money') }
103
+ it { expect( subject ).to include('user') }
104
+ end
105
+
106
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zaim::User do
4
+
5
+ let(:request_url) { 'https://api.zaim.net/v2/home/user/verify' }
6
+ let(:response_headers) { { content_type: 'application/json' } }
7
+ let(:response_body) { File.read('spec/fixtures/user/verify.json') }
8
+ let(:response) { { body: response_body, status: 200, headers: response_headers } }
9
+ let(:client) { Zaim::Client.new }
10
+
11
+ describe "#verify" do
12
+
13
+ before do
14
+ stub_request( :get, request_url ).to_return( response )
15
+ end
16
+
17
+ subject { client.verify }
18
+
19
+ it { expect( subject ).to be_an_instance_of Hash }
20
+ it { expect( subject ).to include('requested') }
21
+ it { expect( subject ).to include('me') }
22
+
23
+ context "response 'me'" do
24
+
25
+ %w( id login name input_count day_count repeat_count day week month currency_code ).each do |key_name|
26
+ it { expect( subject.fetch 'me' ).to include(key_name) }
27
+ end
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zaim do
4
+ it 'should have a version number' do
5
+ Zaim::VERSION.should_not be_nil
6
+ end
7
+
8
+ describe ".configure" do
9
+
10
+ [ :consumer_key, :consumer_secret, :oauth_token, :oauth_token_secret ].each do |attr_name|
11
+
12
+ context "set #{ attr_name }"do
13
+
14
+ before do
15
+ Zaim.configure do |config|
16
+ config.send("#{ attr_name }=", attr_name)
17
+ end
18
+ end
19
+
20
+ subject(:attribute) { Zaim.instance_variable_get(:"@#{ attr_name }") }
21
+
22
+ it { expect(attribute).to eq attr_name }
23
+ end
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,7 @@
1
+ desc "Generate code examples statistics"
2
+ task :coverage do
3
+ ENV['COVERAGE'] = 'true'
4
+
5
+ Rake::Task['spec'].execute
6
+ end
7
+
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zaim/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "zaim"
8
+ spec.version = Zaim::VERSION
9
+ spec.authors = ["toshiwo"]
10
+ spec.email = ["toshiwo@toshiwo.com"]
11
+ spec.description = %q{A Ruby wrapper for the Zaim API.}
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/toshiwo/zaim"
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_runtime_dependency 'faraday', '~> 0.8.7'
22
+ spec.add_runtime_dependency 'faraday_middleware', '~> 0.9.0'
23
+ spec.add_runtime_dependency 'simple_oauth', '~> 0.2.0'
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec", ">= 2.11.0"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency 'webmock'
29
+ spec.add_development_dependency 'json_spec'
30
+ end
metadata ADDED
@@ -0,0 +1,224 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zaim
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - toshiwo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: simple_oauth
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
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: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: 2.11.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: 2.11.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
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
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: json_spec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: A Ruby wrapper for the Zaim API.
140
+ email:
141
+ - toshiwo@toshiwo.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - .gitignore
147
+ - .travis.yml
148
+ - Gemfile
149
+ - LICENSE.txt
150
+ - README.md
151
+ - Rakefile
152
+ - lib/zaim.rb
153
+ - lib/zaim/account.rb
154
+ - lib/zaim/category.rb
155
+ - lib/zaim/client.rb
156
+ - lib/zaim/configuration.rb
157
+ - lib/zaim/genre.rb
158
+ - lib/zaim/money.rb
159
+ - lib/zaim/request.rb
160
+ - lib/zaim/user.rb
161
+ - lib/zaim/version.rb
162
+ - spec/fixtures/account.json
163
+ - spec/fixtures/category.json
164
+ - spec/fixtures/genre.json
165
+ - spec/fixtures/money.json
166
+ - spec/fixtures/money/income.json
167
+ - spec/fixtures/money/payment.json
168
+ - spec/fixtures/money/transfer.json
169
+ - spec/fixtures/user/verify.json
170
+ - spec/spec_helper.rb
171
+ - spec/zaim/account_spec.rb
172
+ - spec/zaim/category_spec.rb
173
+ - spec/zaim/client_spec.rb
174
+ - spec/zaim/genre_spec.rb
175
+ - spec/zaim/money/delete_spec.rb
176
+ - spec/zaim/money/update_spec.rb
177
+ - spec/zaim/money_spec.rb
178
+ - spec/zaim/user_spec.rb
179
+ - spec/zaim_spec.rb
180
+ - tasks/spec.rake
181
+ - zaim.gemspec
182
+ homepage: https://github.com/toshiwo/zaim
183
+ licenses:
184
+ - MIT
185
+ metadata: {}
186
+ post_install_message:
187
+ rdoc_options: []
188
+ require_paths:
189
+ - lib
190
+ required_ruby_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ required_rubygems_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - '>='
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ requirements: []
201
+ rubyforge_project:
202
+ rubygems_version: 2.0.2
203
+ signing_key:
204
+ specification_version: 4
205
+ summary: A Ruby wrapper for the Zaim API.
206
+ test_files:
207
+ - spec/fixtures/account.json
208
+ - spec/fixtures/category.json
209
+ - spec/fixtures/genre.json
210
+ - spec/fixtures/money.json
211
+ - spec/fixtures/money/income.json
212
+ - spec/fixtures/money/payment.json
213
+ - spec/fixtures/money/transfer.json
214
+ - spec/fixtures/user/verify.json
215
+ - spec/spec_helper.rb
216
+ - spec/zaim/account_spec.rb
217
+ - spec/zaim/category_spec.rb
218
+ - spec/zaim/client_spec.rb
219
+ - spec/zaim/genre_spec.rb
220
+ - spec/zaim/money/delete_spec.rb
221
+ - spec/zaim/money/update_spec.rb
222
+ - spec/zaim/money_spec.rb
223
+ - spec/zaim/user_spec.rb
224
+ - spec/zaim_spec.rb