cuenote-api 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/cuenote-api.gemspec +1 -0
- data/lib/cuenote/api.rb +11 -9
- data/lib/cuenote/api/address.rb +20 -0
- data/lib/cuenote/api/address_book.rb +50 -0
- data/lib/cuenote/api/base.rb +15 -4
- data/lib/cuenote/api/command.rb +36 -0
- data/lib/cuenote/api/config.rb +1 -1
- data/lib/cuenote/api/connection.rb +61 -6
- data/lib/cuenote/api/import.rb +8 -12
- data/lib/cuenote/api/node.rb +30 -0
- data/lib/cuenote/api/result.rb +10 -0
- data/lib/cuenote/api/version.rb +1 -1
- data/spec/integration/address_spec.rb +24 -0
- data/spec/lib/cuenote/api/command_spec.rb +17 -0
- data/spec/lib/cuenote/api/config_spec.rb +14 -6
- data/spec/spec_helper.rb +2 -0
- metadata +25 -11
- data/lib/cuenote/api/request.rb +0 -46
- data/lib/cuenote/api/response.rb +0 -31
- data/lib/cuenote/api/xml_builder.rb +0 -44
- data/spec/lib/cuenote/api/request_spec.rb +0 -11
- data/spec/lib/cuenote/api/response_spec.rb +0 -14
- data/spec/lib/cuenote/api/xml_builder_spec.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e13e1ff0ab47c0b200e4b8b142b694b47f70d0e2
|
4
|
+
data.tar.gz: f794e4f57ef44556995fb4d4a3e55b3382fc570e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96101fff168ed0d3f4a471eef16db2d6c7b6e3c84afe2bace5dc44bbb5ddd769c8a058162ac03e6786d6c69ff23ee32165e44033114697fa4fbc203879e71176
|
7
|
+
data.tar.gz: 361e5b1b967724b89cc18c83dc22325efb6d95795b379ca0652735161d5014590747f5628d56910a03fbc89adfffde38b98e388d09c2b4c46fcedb423bffc532
|
data/.gitignore
CHANGED
data/cuenote-api.gemspec
CHANGED
data/lib/cuenote/api.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
require "cuenote/api/version"
|
2
|
+
|
3
|
+
# Config
|
2
4
|
require "cuenote/api/config"
|
3
|
-
require "cuenote/api/xml_builder"
|
4
|
-
require "cuenote/api/request"
|
5
|
-
require "cuenote/api/response"
|
6
|
-
require "cuenote/api/import"
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
# Utility
|
7
|
+
require "cuenote/api/command"
|
8
|
+
require "cuenote/api/connection"
|
9
|
+
require "cuenote/api/node"
|
10
|
+
|
11
|
+
# Api Object
|
12
|
+
require "cuenote/api/address_book"
|
13
|
+
require "cuenote/api/address"
|
14
|
+
require "cuenote/api/import"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "cuenote-api"
|
2
|
+
|
3
|
+
module Cuenote::Api
|
4
|
+
class Address
|
5
|
+
def initialize(element=nil)
|
6
|
+
@element = element
|
7
|
+
# @adbook = element.attributes[:adbook]
|
8
|
+
end
|
9
|
+
|
10
|
+
# TODO
|
11
|
+
def update
|
12
|
+
run 'editAddress'
|
13
|
+
end
|
14
|
+
|
15
|
+
# TODO
|
16
|
+
def delete
|
17
|
+
run 'deleteAddress'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "cuenote/api/node"
|
2
|
+
|
3
|
+
module Cuenote::Api
|
4
|
+
class AddressBook < Node
|
5
|
+
def initialize(doc=nil)
|
6
|
+
super doc
|
7
|
+
@adbook = attributes[:adbook]
|
8
|
+
puts doc.class
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.list
|
12
|
+
res = run 'getAdBookList'
|
13
|
+
res.elements.map do |element|
|
14
|
+
AddressBook.new(element)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# TODO
|
19
|
+
def self.create
|
20
|
+
end
|
21
|
+
|
22
|
+
# TODO
|
23
|
+
def update
|
24
|
+
end
|
25
|
+
|
26
|
+
# TODO
|
27
|
+
def delete
|
28
|
+
end
|
29
|
+
|
30
|
+
# TODO
|
31
|
+
def information
|
32
|
+
end
|
33
|
+
|
34
|
+
# TODO
|
35
|
+
def addresses
|
36
|
+
end
|
37
|
+
|
38
|
+
# TODO
|
39
|
+
def add
|
40
|
+
end
|
41
|
+
|
42
|
+
# TODO
|
43
|
+
def select
|
44
|
+
end
|
45
|
+
|
46
|
+
def import
|
47
|
+
@import ||= Import.new(adbook: @adbook)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/cuenote/api/base.rb
CHANGED
@@ -1,11 +1,22 @@
|
|
1
|
-
require "cuenote/api/
|
2
|
-
require "cuenote/api/response"
|
1
|
+
require "cuenote/api/command"
|
3
2
|
require "cuenote/api/connection"
|
4
3
|
|
5
4
|
module Cuenote::Api
|
6
5
|
class Base
|
7
|
-
def connection
|
8
|
-
Connection.new
|
6
|
+
def self.connection(command)
|
7
|
+
Connection.new(command)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.run(command, params={})
|
11
|
+
connection(Command.new(command, params)).response
|
12
|
+
end
|
13
|
+
|
14
|
+
def connection(command)
|
15
|
+
self.class.connection command
|
16
|
+
end
|
17
|
+
|
18
|
+
def run(command, params={})
|
19
|
+
self.class.run command, params
|
9
20
|
end
|
10
21
|
end
|
11
22
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "builder"
|
2
|
+
|
3
|
+
module Cuenote::Api
|
4
|
+
class Command
|
5
|
+
def initialize(command, params={})
|
6
|
+
@command, @params = [command, params]
|
7
|
+
end
|
8
|
+
|
9
|
+
def builder
|
10
|
+
@builder ||= ::Builder::XmlMarkup.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def build(id)
|
14
|
+
build_command @command, id, @params
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def build_command command, id, params
|
20
|
+
options = {}
|
21
|
+
options[:id] = id if id
|
22
|
+
options[:command] = command
|
23
|
+
if params && params.size > 0
|
24
|
+
builder.execute options do |exec|
|
25
|
+
exec.parameter do |parameter|
|
26
|
+
params.each do |key, val|
|
27
|
+
eval "parameter.#{key} \"#{val}\""
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
else
|
32
|
+
builder.execute options
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/cuenote/api/config.rb
CHANGED
@@ -1,11 +1,66 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "builder"
|
3
|
+
|
4
|
+
require "cuenote/api/command"
|
5
|
+
require "cuenote/api/result"
|
6
|
+
|
1
7
|
module Cuenote::Api
|
2
8
|
class Connection
|
3
|
-
def
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
def initialize *commands
|
10
|
+
@commands = commands
|
11
|
+
end
|
12
|
+
|
13
|
+
def send
|
14
|
+
Net::HTTP.start uri.hostname, uri.port, use_ssl: (uri.scheme == 'https') do |http|
|
15
|
+
http.request request
|
16
|
+
end.tap {|res| puts res.body }
|
17
|
+
end
|
18
|
+
|
19
|
+
def response
|
20
|
+
@response ||= Result.new(send.body)
|
21
|
+
end
|
22
|
+
|
23
|
+
def request
|
24
|
+
req = Net::HTTP::Post.new(uri)
|
25
|
+
req.basic_auth username, password
|
26
|
+
req.content_type = 'form-data'
|
27
|
+
req.body = body.map{|k,v| "#{k}=#{v}" }.join("&")
|
28
|
+
req
|
29
|
+
end
|
30
|
+
|
31
|
+
def builder
|
32
|
+
@builder ||= ::Builder::XmlMarkup.new
|
33
|
+
end
|
34
|
+
|
35
|
+
def body
|
36
|
+
{
|
37
|
+
CCC: "愛",
|
38
|
+
xml: build
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def build
|
43
|
+
builder.forcast do |forcast|
|
44
|
+
@commands.map.with_index do |command, id|
|
45
|
+
forcast << command.build(id)
|
46
|
+
end
|
47
|
+
end.tap{|xml| puts xml }
|
48
|
+
end
|
49
|
+
|
50
|
+
def uri
|
51
|
+
@uri ||= URI(config.endpoint)
|
52
|
+
end
|
53
|
+
|
54
|
+
def username
|
55
|
+
config.username
|
56
|
+
end
|
57
|
+
|
58
|
+
def password
|
59
|
+
config.password
|
60
|
+
end
|
61
|
+
|
62
|
+
def config
|
63
|
+
Cuenote::Api.config
|
9
64
|
end
|
10
65
|
end
|
11
66
|
end
|
data/lib/cuenote/api/import.rb
CHANGED
@@ -2,29 +2,25 @@ require "cuenote/api/base"
|
|
2
2
|
|
3
3
|
module Cuenote::Api
|
4
4
|
class Import < Base
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(params={})
|
6
|
+
@params = params
|
7
7
|
end
|
8
8
|
|
9
|
-
def set
|
10
|
-
|
11
|
-
req.add_command 'setImportEntry', 1, @options
|
12
|
-
res = connection.send req
|
9
|
+
def set params={}
|
10
|
+
res = run 'setImportEntry', @params.merge(params)
|
13
11
|
@impid = res.attributes[:impid]
|
14
12
|
end
|
15
13
|
|
16
|
-
def get
|
14
|
+
def get params={}
|
17
15
|
@impid
|
18
16
|
end
|
19
17
|
|
20
|
-
def test
|
18
|
+
def test params={}
|
21
19
|
@impid
|
22
20
|
end
|
23
21
|
|
24
|
-
def start
|
25
|
-
|
26
|
-
req.add_command 'startImportEntry', 1, impid: @impid
|
27
|
-
res = connection.send req
|
22
|
+
def start params={}
|
23
|
+
run 'startImportEntry', params.merge(impid: @impid)
|
28
24
|
end
|
29
25
|
end
|
30
26
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
require "cuenote/api/base"
|
4
|
+
|
5
|
+
module Cuenote::Api
|
6
|
+
class Node < Base
|
7
|
+
def initialize(doc=nil)
|
8
|
+
@doc =
|
9
|
+
case doc
|
10
|
+
when REXML::Element
|
11
|
+
doc
|
12
|
+
when String
|
13
|
+
REXML::Document.new(doc)
|
14
|
+
else
|
15
|
+
REXML::Document.new('<a/>')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def attributes
|
20
|
+
@attributes ||= @doc.attributes.inject({}) do
|
21
|
+
|hash, attr| hash[attr[0].to_sym] = attr[1]
|
22
|
+
hash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def elements
|
27
|
+
@doc.elements
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/cuenote/api/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
describe "get address" do
|
2
|
+
before do
|
3
|
+
Cuenote::Api.configure do |config|
|
4
|
+
config.endpoint = ENV['CUENOTE_ENDPOINT']
|
5
|
+
config.username = ENV['CUENOTE_USERNAME']
|
6
|
+
config.password = ENV['CUENOTE_PASSWORD']
|
7
|
+
end
|
8
|
+
WebMock.disable!
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
WebMock.enable!
|
13
|
+
end
|
14
|
+
|
15
|
+
it "get address book" do
|
16
|
+
books = Cuenote::Api::AddressBook.list
|
17
|
+
book = books[0]
|
18
|
+
|
19
|
+
expect(book).to be_a_kind_of Cuenote::Api::AddressBook
|
20
|
+
|
21
|
+
import = book.import
|
22
|
+
expect(import).to be_a_kind_of Cuenote::Api::Import
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Cuenote::Api::Command do
|
4
|
+
it "build xml" do
|
5
|
+
@builder = Cuenote::Api::Command.new 'command', { key: 'val' }
|
6
|
+
expect(@builder.build(1)).to eq <<-XML.chomp
|
7
|
+
<execute id="1" command="command"><parameter><key>val</key></parameter></execute>
|
8
|
+
XML
|
9
|
+
end
|
10
|
+
|
11
|
+
it "build xml without params" do
|
12
|
+
@builder = Cuenote::Api::Command.new 'command'
|
13
|
+
expect(@builder.build(1)).to eq <<-XML.chomp
|
14
|
+
<execute id="1" command="command"/>
|
15
|
+
XML
|
16
|
+
end
|
17
|
+
end
|
@@ -1,10 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
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
4
|
it "changed config" do
|
9
5
|
Cuenote::Api.config.endpoint "https://hoge.asp.cuenote.jp/api/fcio.cgi"
|
10
6
|
expect(Cuenote::Api.config.endpoint).to eq "https://hoge.asp.cuenote.jp/api/fcio.cgi"
|
@@ -12,8 +8,20 @@ describe Cuenote::Api::Config do
|
|
12
8
|
|
13
9
|
it "changed config with configure" do
|
14
10
|
Cuenote::Api.configure do |config|
|
15
|
-
config.endpoint "https://
|
11
|
+
config.endpoint "https://moge.asp.cuenote.jp/api/fcio.cgi"
|
16
12
|
end
|
17
|
-
expect(Cuenote::Api.config.endpoint).to eq "https://
|
13
|
+
expect(Cuenote::Api.config.endpoint).to eq "https://moge.asp.cuenote.jp/api/fcio.cgi"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "changed config use equal" do
|
17
|
+
Cuenote::Api.config.endpoint = "https://fuga.asp.cuenote.jp/api/fcio.cgi"
|
18
|
+
expect(Cuenote::Api.config.endpoint).to eq "https://fuga.asp.cuenote.jp/api/fcio.cgi"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "changed config with configure use equal" do
|
22
|
+
Cuenote::Api.configure do |config|
|
23
|
+
config.endpoint = "https://hage.asp.cuenote.jp/api/fcio.cgi"
|
24
|
+
end
|
25
|
+
expect(Cuenote::Api.config.endpoint).to eq "https://hage.asp.cuenote.jp/api/fcio.cgi"
|
18
26
|
end
|
19
27
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuenote-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eido NABESHIMA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: builder
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: dotenv
|
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'
|
83
97
|
description: Cuenote API
|
84
98
|
email:
|
85
99
|
- closer009@gmail.com
|
@@ -95,18 +109,19 @@ files:
|
|
95
109
|
- cuenote-api.gemspec
|
96
110
|
- lib/cuenote-api.rb
|
97
111
|
- lib/cuenote/api.rb
|
112
|
+
- lib/cuenote/api/address.rb
|
113
|
+
- lib/cuenote/api/address_book.rb
|
98
114
|
- lib/cuenote/api/base.rb
|
115
|
+
- lib/cuenote/api/command.rb
|
99
116
|
- lib/cuenote/api/config.rb
|
100
117
|
- lib/cuenote/api/connection.rb
|
101
118
|
- lib/cuenote/api/import.rb
|
102
|
-
- lib/cuenote/api/
|
103
|
-
- lib/cuenote/api/
|
119
|
+
- lib/cuenote/api/node.rb
|
120
|
+
- lib/cuenote/api/result.rb
|
104
121
|
- lib/cuenote/api/version.rb
|
105
|
-
-
|
122
|
+
- spec/integration/address_spec.rb
|
123
|
+
- spec/lib/cuenote/api/command_spec.rb
|
106
124
|
- 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
125
|
- spec/spec_helper.rb
|
111
126
|
homepage: ''
|
112
127
|
licenses:
|
@@ -133,9 +148,8 @@ signing_key:
|
|
133
148
|
specification_version: 4
|
134
149
|
summary: Cuenote API
|
135
150
|
test_files:
|
151
|
+
- spec/integration/address_spec.rb
|
152
|
+
- spec/lib/cuenote/api/command_spec.rb
|
136
153
|
- 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
154
|
- spec/spec_helper.rb
|
141
155
|
has_rdoc:
|
data/lib/cuenote/api/request.rb
DELETED
@@ -1,46 +0,0 @@
|
|
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
|
data/lib/cuenote/api/response.rb
DELETED
@@ -1,31 +0,0 @@
|
|
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
|
@@ -1,44 +0,0 @@
|
|
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
|
@@ -1,14 +0,0 @@
|
|
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
|
@@ -1,35 +0,0 @@
|
|
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
|