cuenote-api 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: 1cd3c4eab536a75bb59577df76347b44438c2ccd
4
+ data.tar.gz: 8196278e54826a5e534337262ad9f29a3218869d
5
+ SHA512:
6
+ metadata.gz: 1e5d32aa49fc3856df540c11d7f9ee31b4ef806ea9836f0284d5bf0f125624bd9600b81b84cd8ac6aa82c985dd0aa7543da8b009a10ac4b42554c6cc599360ba
7
+ data.tar.gz: 51b2bb5ed87833b62c3af7e34d7f0824975c21e47f44bb1b2c84aa64fda30a508b8fa8f54e80d91b82dbe395bca9a40a7bd7f6cb6c20cf8e2ce56263028aa462
@@ -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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cuenote-api.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Eido NABESHIMA
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,29 @@
1
+ # Cuenote::Api
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cuenote-api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cuenote-api
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/cuenote-api/fork )
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
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cuenote/api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cuenote-api"
8
+ spec.version = Cuenote::Api::VERSION
9
+ spec.authors = ["Eido NABESHIMA"]
10
+ spec.email = ["closer009@gmail.com"]
11
+ spec.summary = %q{Cuenote API}
12
+ spec.description = %q{Cuenote API}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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 "builder", "~> 3.2.2"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "webmock"
27
+ end
@@ -0,0 +1 @@
1
+ require "cuenote/api"
@@ -0,0 +1,11 @@
1
+ require "cuenote/api/version"
2
+ require "cuenote/api/config"
3
+ require "cuenote/api/xml_builder"
4
+ require "cuenote/api/request"
5
+ require "cuenote/api/response"
6
+
7
+ module Cuenote
8
+ module Api
9
+ # Your code goes here...
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ require "cuenote/api/request"
2
+ require "cuenote/api/response"
3
+
4
+ module Cuenote::Api
5
+ class Base
6
+ def connection
7
+ Connection.new
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,35 @@
1
+ module Cuenote::Api
2
+ CONFIG_DEFAULT = {
3
+ endpoint: "http://asp.cuenote.jp/api/fcio.cgi"
4
+ }.freeze
5
+
6
+ class Config
7
+ def initialize
8
+ @config = CONFIG_DEFAULT.dup
9
+ end
10
+
11
+ def method_missing name, value=nil
12
+ if value
13
+ set name, value
14
+ else
15
+ get name
16
+ end
17
+ end
18
+
19
+ def set name, value
20
+ @config[name.to_sym] = value
21
+ end
22
+
23
+ def get name
24
+ @config[name.to_sym]
25
+ end
26
+ end
27
+
28
+ def self.config
29
+ @config ||= Config.new
30
+ end
31
+
32
+ def self.configure &block
33
+ block.call config
34
+ end
35
+ end
@@ -0,0 +1,10 @@
1
+ module Cuenote::Api
2
+ class Connection
3
+ def send(req)
4
+ response = Net::HTTP.start uri.hostname, uri.port, use_ssl: (uri.scheme == 'https') do |http|
5
+ http.request req
6
+ end
7
+ Response.new response
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ require "cuenote/api/base"
2
+
3
+ module Cuenote::Api
4
+ class Import < Base
5
+ def initialize(options={})
6
+ @options = options
7
+ end
8
+
9
+ def set
10
+ req = Request.new
11
+ req.add_command 'setImportEntry', 1, @options
12
+ res = connection.send req
13
+ @impid = res.attributes[:impid]
14
+ end
15
+
16
+ def get
17
+ @impid
18
+ end
19
+
20
+ def test
21
+ @impid
22
+ end
23
+
24
+ def start
25
+ req = Request.new
26
+ req.add_command 'startImportEntry', 1, impid: @impid
27
+ res = connection.send req
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,46 @@
1
+ require "cuenote/api/xml_builder"
2
+ require "cuenote/api/config"
3
+ require 'net/http'
4
+
5
+ module Cuenote::Api
6
+ class Request
7
+ def req
8
+ req = Net::HTTP::Post.new(uri)
9
+ req.basic_auth user, password
10
+ req.content_type = 'form-data'
11
+ req.body = body
12
+ req
13
+ end
14
+
15
+ def add_command command, id, params
16
+ builder.add_command command, id, params
17
+ end
18
+
19
+ def builder
20
+ @builder ||= Cuenote::Api::XmlBuilder.new
21
+ end
22
+
23
+ def body
24
+ {
25
+ CCC: "愛",
26
+ xml: builder.build
27
+ }
28
+ end
29
+
30
+ def uri
31
+ @uri ||= URI(config.endpoint)
32
+ end
33
+
34
+ def user
35
+ config.user
36
+ end
37
+
38
+ def password
39
+ config.password
40
+ end
41
+
42
+ def config
43
+ Cuenote::Api.config
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,31 @@
1
+ require 'rexml/document'
2
+
3
+ module Cuenote::Api
4
+ class Response
5
+ def initialize(response)
6
+ @response = response
7
+ end
8
+
9
+ def attributes
10
+ @attributes ||= result.attributes.inject({}) do
11
+ |hash, attr| hash[attr[0].to_sym] = attr[1]
12
+ hash
13
+ end
14
+ end
15
+
16
+ def params
17
+ @params ||= result.elements.map.inject({}) do |hash, element|
18
+ hash[element.name.to_sym] = element.text
19
+ hash
20
+ end
21
+ end
22
+
23
+ def result
24
+ @result ||= doc.elements['forecast/result']
25
+ end
26
+
27
+ def doc
28
+ @doc ||= REXML::Document.new @response.body
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module Cuenote
2
+ module Api
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,44 @@
1
+ require "builder"
2
+
3
+ module Cuenote
4
+ module Api
5
+ class XmlBuilder
6
+ def initialize
7
+ @builder = ::Builder::XmlMarkup.new
8
+ @commands = []
9
+ end
10
+
11
+ def add_command command, id=nil, params=nil
12
+ id, params = [nil, id] if id && !params && Hash === id
13
+ @commands << [command, id, params]
14
+ end
15
+
16
+ def build
17
+ @builder.forecast do |forecast|
18
+ @commands.each do |command, id, params|
19
+ build_command command, id, params
20
+ end
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def build_command command, id, params
27
+ options = {}
28
+ options[:id] = id if id
29
+ options[:command] = command
30
+ if params
31
+ @builder.execute options do |exec|
32
+ exec.parameter do |parameter|
33
+ params.each do |key, val|
34
+ eval "parameter.#{key} #{val}"
35
+ end
36
+ end
37
+ end
38
+ else
39
+ @builder.execute options
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe Cuenote::Api::Config do
4
+ it "default config" do
5
+ expect(Cuenote::Api.config.endpoint).to eq "http://asp.cuenote.jp/api/fcio.cgi"
6
+ end
7
+
8
+ it "changed config" do
9
+ Cuenote::Api.config.endpoint "https://hoge.asp.cuenote.jp/api/fcio.cgi"
10
+ expect(Cuenote::Api.config.endpoint).to eq "https://hoge.asp.cuenote.jp/api/fcio.cgi"
11
+ end
12
+
13
+ it "changed config with configure" do
14
+ Cuenote::Api.configure do |config|
15
+ config.endpoint "https://hoge.asp.cuenote.jp/api/fcio.cgi"
16
+ end
17
+ expect(Cuenote::Api.config.endpoint).to eq "https://hoge.asp.cuenote.jp/api/fcio.cgi"
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe Cuenote::Api::Request do
4
+ before do
5
+ @request = Cuenote::Api::Request.new
6
+ end
7
+
8
+ it "send" do
9
+ stub_request(:any, Cuenote::Api.config.endpoint)
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ describe Cuenote::Api::Response do
4
+ before do
5
+ end
6
+
7
+ it do
8
+ stub_request(:any, Cuenote::Api.config.endpoint)
9
+ .to_return(body: '<forecast><result command="setImportEntry" id="1"> <impid>1</impid><status>ok</status> <statuscode>1</statuscode></result></forecast>')
10
+ request = Cuenote::Api::Request.new
11
+ # expect(@response.attributes).to eq({ command: "setImportEntry", id: '1'})
12
+ # expect(@response.params).to eq({ impid: '1', status: 'ok', statuscode: '1' })
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe Cuenote::Api::XmlBuilder do
4
+ before do
5
+ @builder = Cuenote::Api::XmlBuilder.new
6
+ end
7
+
8
+ it "build xml" do
9
+ @builder.add_command 'command', 1, { key: 'val' }
10
+ expect(@builder.build).to eq <<-XML.chomp
11
+ <forecast><execute id="1" command="command"><parameter><key>val</key></parameter></execute></forecast>
12
+ XML
13
+ end
14
+
15
+ it "build xml without id" do
16
+ @builder.add_command 'command', { key: 'val' }
17
+ expect(@builder.build).to eq <<-XML.chomp
18
+ <forecast><execute command="command"><parameter><key>val</key></parameter></execute></forecast>
19
+ XML
20
+ end
21
+
22
+ it "build xml without params" do
23
+ @builder.add_command 'command', 1
24
+ expect(@builder.build).to eq <<-XML.chomp
25
+ <forecast><execute id="1" command="command"/></forecast>
26
+ XML
27
+ end
28
+
29
+ it "build xml only command name" do
30
+ @builder.add_command 'command'
31
+ expect(@builder.build).to eq <<-XML.chomp
32
+ <forecast><execute command="command"/></forecast>
33
+ XML
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ require "cuenote-api"
2
+ require 'webmock/rspec'
3
+
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cuenote-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eido NABESHIMA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: builder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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: 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: webmock
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
+ description: Cuenote API
84
+ email:
85
+ - closer009@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - cuenote-api.gemspec
96
+ - lib/cuenote-api.rb
97
+ - lib/cuenote/api.rb
98
+ - lib/cuenote/api/base.rb
99
+ - lib/cuenote/api/config.rb
100
+ - lib/cuenote/api/connection.rb
101
+ - lib/cuenote/api/import.rb
102
+ - lib/cuenote/api/request.rb
103
+ - lib/cuenote/api/response.rb
104
+ - lib/cuenote/api/version.rb
105
+ - lib/cuenote/api/xml_builder.rb
106
+ - spec/lib/cuenote/api/config_spec.rb
107
+ - spec/lib/cuenote/api/request_spec.rb
108
+ - spec/lib/cuenote/api/response_spec.rb
109
+ - spec/lib/cuenote/api/xml_builder_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: ''
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.0.3
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Cuenote API
135
+ test_files:
136
+ - spec/lib/cuenote/api/config_spec.rb
137
+ - spec/lib/cuenote/api/request_spec.rb
138
+ - spec/lib/cuenote/api/response_spec.rb
139
+ - spec/lib/cuenote/api/xml_builder_spec.rb
140
+ - spec/spec_helper.rb
141
+ has_rdoc: