sakenote 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a9afa506024e4311f67846b8bc10d66b17c4e202
4
+ data.tar.gz: 15fdff9bf8e3c2626231623a573ce76684f9808c
5
+ SHA512:
6
+ metadata.gz: 3b5bf0df6c5a7eb0aed575ba1af9fe0ee5ac61d2d323e5053d75582efe3686f99fb1b124e65cea659af623e85dc3c176ee2ad33bb37c3df6968a3e3e5f850e89
7
+ data.tar.gz: 90498d6dba4c053fcd62c2948d7922b3d4c98ecec1b2dae2ec529b67a97f1b4e7af1ed485a7c718f60b7462b5a4ec20155164685901318c2cde62aa31fdffa07
@@ -0,0 +1 @@
1
+ SAKENOTE_TOKEN=*******
@@ -0,0 +1,19 @@
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
18
+
19
+ .env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sakenote.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 fukayatsu
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,72 @@
1
+ # Sakenote
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sakenote'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sakenote
18
+
19
+ ## Usage
20
+
21
+ - [get access token](https://www.sakenote.com/access_tokens)
22
+ - [Sakenote API v1 docs](http://docs.sakenote.apiary.io/)
23
+
24
+ ```ruby
25
+ require 'sakenote'
26
+
27
+ # initialize client
28
+ client = Sakenote::Client.new('YOUR SAKENOTE TOKEN')
29
+
30
+ # search Sake
31
+ # options:
32
+ # prefecture_code: 都道府県コード(integer)
33
+ # sake_name: 銘柄の名前(string)
34
+ # maker_name: 酒造の名前(string)
35
+ # page: 取得するページ番号(integer)
36
+ search_result = client.sakes(sake_name: '雪の茅舎')
37
+ puts search_result.num_pages #=> 1
38
+
39
+ sake = search_result.list.first
40
+ puts sake.identify_code #=> 'P002384'
41
+ puts sake.name #=> '雪の茅舎'
42
+ puts sake.furigana #=> 'ゆきのぼうしゃ'
43
+ puts sake.alphabet #=> 'yukinobousha'
44
+
45
+ maker = sake.maker
46
+ puts maker.name #=> '齋彌酒造店'
47
+ puts maker.postcode #=> '036-8366'
48
+ puts maker.address #=> '秋田県由利本荘市石脇字石脇53'
49
+ puts maker.url #=> 'http://www.yukinobousha.jp/'
50
+
51
+ # search Maker
52
+ # options:
53
+ # prefecture_code: 都道府県コード(integer)
54
+ # maker_name: 酒造の名前(string)
55
+ # page: 取得するページ番号(integer)
56
+ search_result = client.makers(prefecture_code: 05) # 05: Akita (ISO 3166-2:JP)
57
+ puts search_result.num_pages #=> 1
58
+
59
+ maker = search_result.list[1]
60
+ puts maker.name #=> '阿桜酒造'
61
+ puts maker.postcode #=> '013-0041'
62
+ puts maker.address #=> '秋田県横手市大沢字西野67-2'
63
+ puts maker.url #=> 'http://www.azakura.co.jp/'
64
+ ```
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ require "sakenote/version"
2
+ require 'sakenote/client'
3
+
@@ -0,0 +1,84 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ require 'sakenote/error'
5
+ require 'sakenote/error/configuration_error'
6
+ require 'sakenote/search_result'
7
+ require 'sakenote/sake'
8
+ require 'sakenote/maker'
9
+
10
+ module Sakenote
11
+ class Client
12
+ def initialize(token)
13
+ if token.is_a?(String) && token.strip.length > 0
14
+ @token = token
15
+ @conn = connection
16
+ else
17
+ raise Sakenote::Error::ConfigurationError
18
+ end
19
+ end
20
+
21
+ # https://www.sakenote.com/api/v1/sakes
22
+ def sakes(prefecture_code: nil, sake_name: nil, maker_name: nil, page: 1)
23
+ options = {
24
+ token: @token,
25
+ prefecture_code: prefecture_code,
26
+ sake_name: sake_name,
27
+ maker_name: maker_name,
28
+ page: page
29
+ }.select{ |k, v| !v.nil? }
30
+
31
+ response = @conn.get '/api/v1/sakes', options
32
+
33
+ num_pages = response.body['num_pages'].to_i
34
+ list = response.body['sakes'].map { |s|
35
+ Sake.new(s['sake_name'],
36
+ identify_code: s['sake_identify_code'],
37
+ furigana: s['sake_furigana'],
38
+ alphabet: s['sake_alphabet'],
39
+ maker: Maker.new(s['maker_name'],
40
+ postcode: s['maker_postcode'],
41
+ address: s['maker_address'],
42
+ url: s['maker_url']
43
+ )
44
+ )
45
+ }
46
+
47
+ SearchResult.new(list, num_pages)
48
+ end
49
+
50
+ # https://www.sakenote.com/api/v1/makers
51
+ def makers(prefecture_code: nil, maker_name: nil, page: 1)
52
+ options = {
53
+ token: @token,
54
+ prefecture_code: prefecture_code,
55
+ maker_name: maker_name,
56
+ page: page
57
+ }.select{ |k, v| !v.nil? }
58
+
59
+ response = @conn.get '/api/v1/makers', options
60
+
61
+ num_pages = response.body['num_pages'].to_i
62
+ list = response.body['makers'].map { |s|
63
+ Maker.new(s['maker_name'],
64
+ postcode: s['maker_postcode'],
65
+ address: s['maker_address'],
66
+ url: s['maker_url']
67
+ )
68
+ }
69
+
70
+ SearchResult.new(list, num_pages)
71
+ end
72
+
73
+ def connection
74
+ faraday = Faraday.new 'https://www.sakenote.com' do |conn|
75
+ conn.request :json
76
+ conn.response :json, :content_type => /\bjson$/
77
+ conn.adapter Faraday.default_adapter
78
+ end
79
+
80
+ faraday.headers[:user_agent] = "Sakenote/#{Sakenote::VERSION} (sakenote-rubygems/#{Sakenote::VERSION})"
81
+ faraday
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,4 @@
1
+ module Sakenote
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,8 @@
1
+ require 'sakenote/error'
2
+
3
+ module Sakenote
4
+ class Error
5
+ class ConfigurationError < ::ArgumentError
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ module Sakenote
2
+ class Maker
3
+ def initialize(name, postcode: nil, address: nil, url: nil)
4
+ @name = name
5
+ @postcode = postcode
6
+ @address = address
7
+ @url = url
8
+ end
9
+
10
+ attr_reader :name, :postcode, :address, :url
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module Sakenote
2
+ class Sake
3
+ def initialize(name, identify_code: nil, furigana: nil, alphabet: nil, maker: nil)
4
+ @name = name
5
+ @identify_code = identify_code
6
+ @furigana = furigana
7
+ @alphabet = alphabet
8
+ @maker = maker
9
+ end
10
+
11
+ attr_reader :name, :identify_code, :furigana, :alphabet, :maker
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ module Sakenote
2
+ class SearchResult
3
+ def initialize(list, num_pages)
4
+ @list = list
5
+ @num_pages = num_pages
6
+ end
7
+
8
+ attr_reader :list, :num_pages
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Sakenote
2
+ VERSION = "0.0.1"
3
+ end
data/memo.md ADDED
@@ -0,0 +1,8 @@
1
+ # TODO
2
+ - vcr
3
+ - travis
4
+
5
+ # DOING
6
+
7
+ # DONE
8
+
@@ -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 'sakenote/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sakenote"
8
+ spec.version = Sakenote::VERSION
9
+ spec.authors = ["fukayatsu"]
10
+ spec.email = ["fukayatsu@gmail.com"]
11
+ spec.description = %q{Sakenote API client}
12
+ spec.summary = %q{Sakenote API client}
13
+ spec.homepage = "https://github.com/fukayatsu/sakenote"
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 "faraday", "~> 0.8.8"
22
+ spec.add_dependency "faraday_middleware", "~> 0.9.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec", "~> 2.1"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "dotenv"
29
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sakenote::Client do
4
+ describe '#new' do
5
+ context "token is provided" do
6
+ it 'dose not raise error' do
7
+ expect{
8
+ Sakenote::Client.new('foobar')
9
+ }.to_not raise_error
10
+ end
11
+ end
12
+
13
+ context "when invalid token is provided" do
14
+ it "raises a ConfigurationError exception" do
15
+ expect {
16
+ Sakenote::Client.new(['foo', 'bar'])
17
+ }.to raise_exception(Sakenote::Error::ConfigurationError)
18
+ end
19
+ end
20
+
21
+ context "no token is provided" do
22
+ it "raises a ArgumentError exception" do
23
+ expect {
24
+ Sakenote::Client.new
25
+ }.to raise_exception(ArgumentError)
26
+ end
27
+ end
28
+ end
29
+
30
+ describe '#sakes' do
31
+ before(:all) do
32
+ @client = Sakenote::Client.new(ENV['SAKENOTE_TOKEN'])
33
+ end
34
+
35
+ context 'with no options' do
36
+ before(:all) do
37
+ @sakes = @client.sakes
38
+ end
39
+
40
+ it 'contains list of sakes' do
41
+ expect(@sakes.list[0]).to be_a Sakenote::Sake
42
+ end
43
+
44
+ it 'contains num_pages' do
45
+ expect(@sakes.num_pages).to be > 0
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#makers' do
51
+ before(:all) do
52
+ @client = Sakenote::Client.new(ENV['SAKENOTE_TOKEN'])
53
+ end
54
+
55
+ context 'with no options' do
56
+ before(:all) do
57
+ @makers = @client.makers
58
+ end
59
+
60
+ it 'contains list of makers' do
61
+ expect(@makers.list[0]).to be_a Sakenote::Maker
62
+ end
63
+
64
+ it 'contains num_pages' do
65
+ expect(@makers.num_pages).to be > 0
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sakenote do
4
+ it 'VERSION' do
5
+ expect(Sakenote::VERSION).to eq('0.0.1')
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ require 'sakenote'
2
+ require 'dotenv'
3
+ Dotenv.load
4
+
5
+
6
+ # This file was generated by the `rspec --init` command. Conventionally, all
7
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
+ # Require this file using `require "spec_helper"` to ensure that it is only
9
+ # loaded once.
10
+ #
11
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sakenote
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - fukayatsu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-15 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.8
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.8
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '2.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '2.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
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: dotenv
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: Sakenote API client
112
+ email:
113
+ - fukayatsu@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .env.sample
119
+ - .gitignore
120
+ - .rspec
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - lib/sakenote.rb
126
+ - lib/sakenote/client.rb
127
+ - lib/sakenote/error.rb
128
+ - lib/sakenote/error/configuration_error.rb
129
+ - lib/sakenote/maker.rb
130
+ - lib/sakenote/sake.rb
131
+ - lib/sakenote/search_result.rb
132
+ - lib/sakenote/version.rb
133
+ - memo.md
134
+ - sakenote.gemspec
135
+ - spec/sakenote/client_spec.rb
136
+ - spec/sakenote_spec.rb
137
+ - spec/spec_helper.rb
138
+ homepage: https://github.com/fukayatsu/sakenote
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.0.3
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Sakenote API client
162
+ test_files:
163
+ - spec/sakenote/client_spec.rb
164
+ - spec/sakenote_spec.rb
165
+ - spec/spec_helper.rb