collmex-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/collmex.rb +35 -0
- data/lib/collmex/api.rb +361 -0
- data/lib/collmex/api/line.rb +0 -0
- data/lib/collmex/api/lines.rb +0 -0
- data/lib/collmex/request.rb +95 -0
- data/spec/lib/collmex/api_spec.rb +582 -0
- data/spec/lib/collmex/request_spec.rb +160 -0
- data/spec/lib/collmex_spec.rb +54 -0
- data/spec/spec_helper.rb +34 -0
- metadata +68 -0
@@ -0,0 +1,160 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Collmex::Request do
|
4
|
+
|
5
|
+
describe ".run" do
|
6
|
+
it "should return an instance of Colmex::Request" do
|
7
|
+
Collmex::Request.any_instance.stub(:execute)
|
8
|
+
Collmex::Request.run.should be_a Collmex::Request
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should execute a given block" do
|
12
|
+
Collmex::Request.any_instance.stub(:execute)
|
13
|
+
Collmex::Request.any_instance.should_receive(:dump).with("arr").and_return("blaaaa")
|
14
|
+
Collmex::Request.run do
|
15
|
+
dump "arr"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".uri" do
|
21
|
+
subject { Collmex::Request.uri }
|
22
|
+
specify { subject.to_s.should eql "https://www.collmex.de/cgi-bin/cgi.exe?#{Collmex.customer_id},0,data_exchange" }
|
23
|
+
end
|
24
|
+
|
25
|
+
subject { described_class.new }
|
26
|
+
specify { subject.should be_a Collmex::Request }
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
describe "#initialize" do
|
31
|
+
|
32
|
+
it "should add the Login command to its own queue" do
|
33
|
+
request = Collmex::Request.new
|
34
|
+
request.commands.count.should eql 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#add_command" do
|
39
|
+
|
40
|
+
it "should add the given command to its command array" do
|
41
|
+
request = Collmex::Request.new
|
42
|
+
request.should be_a Collmex::Request
|
43
|
+
|
44
|
+
request.commands = Array.new
|
45
|
+
request.add_command "asd"
|
46
|
+
request.commands.count.should eql 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#classfy" do
|
51
|
+
|
52
|
+
subject { Collmex::Request }
|
53
|
+
|
54
|
+
specify do
|
55
|
+
subject.classify(:accdoc_get).should eql "AccdocGet"
|
56
|
+
subject.classify(:accDoc_get).should eql "AccdocGet"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#enqueue" do
|
61
|
+
|
62
|
+
context "given a symbol command" do
|
63
|
+
let(:request) { Collmex::Request.new }
|
64
|
+
|
65
|
+
it "should return a command object" do
|
66
|
+
request.enqueue(:accdoc_get).should be_a Collmex::Api::AccdocGet
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should enqueue the given comands" do
|
70
|
+
initial_count = request.commands.count
|
71
|
+
request.enqueue :accdoc_get
|
72
|
+
request.enqueue :accdoc_get, :accdoc_id => 1
|
73
|
+
request.commands.count.should equal (initial_count + 2)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "given a collmex api line object" do
|
78
|
+
|
79
|
+
let(:request) { Collmex::Request.new }
|
80
|
+
|
81
|
+
it "should retun the command object" do
|
82
|
+
cmd_obj = Collmex::Api::AccdocGet.new()
|
83
|
+
request.enqueue(cmd_obj).should eql cmd_obj
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should enqueue the command object" do
|
87
|
+
initial_count = request.commands.count
|
88
|
+
cmd_obj = Collmex::Api::AccdocGet.new()
|
89
|
+
request.enqueue cmd_obj
|
90
|
+
request.commands.count.should eql (initial_count + 1)
|
91
|
+
request.commands.last.should eql cmd_obj
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
describe ".execute" do
|
99
|
+
|
100
|
+
before(:each) do
|
101
|
+
Net::HTTP.stub(:new).and_return(http)
|
102
|
+
Net::HTTP.stub(:request_post).and_return(response)
|
103
|
+
Collmex::Api.stub(:parse_line)
|
104
|
+
end
|
105
|
+
|
106
|
+
let(:http) do
|
107
|
+
http = mock(Net::HTTP)
|
108
|
+
http.stub("use_ssl=")
|
109
|
+
http.stub("verify_mode=")
|
110
|
+
http.stub(:request_post).and_return(response)
|
111
|
+
http
|
112
|
+
end
|
113
|
+
|
114
|
+
let(:response) do
|
115
|
+
response = mock(Net::HTTPOK)
|
116
|
+
response.stub(:body).and_return("fuckmehard")
|
117
|
+
response.stub(:code).and_return(200)
|
118
|
+
response
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should create an instance of net::http" do
|
122
|
+
Net::HTTP.should_receive(:new).and_return(http)
|
123
|
+
subject.execute
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should use ssl" do
|
127
|
+
http.should_receive("use_ssl=").with(true)
|
128
|
+
subject.execute
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should not verify ssl" do
|
132
|
+
http.should_receive("verify_mode=").with(OpenSSL::SSL::VERIFY_NONE)
|
133
|
+
subject.execute
|
134
|
+
end
|
135
|
+
|
136
|
+
it "shoud do the post_request" do
|
137
|
+
http.should_receive(:request_post).with(anything,anything,{"Content-Type" => "text/csv"}).and_return(response)
|
138
|
+
subject.execute
|
139
|
+
end
|
140
|
+
|
141
|
+
context "with a working connection" do
|
142
|
+
|
143
|
+
it "should parse the response" do
|
144
|
+
subject.stub(:parse_response).and_return( [Collmex::Api::Accdoc.new])
|
145
|
+
subject.should_receive(:parse_response)
|
146
|
+
subject.execute
|
147
|
+
end
|
148
|
+
it "the response should be encoded in utf-8" do
|
149
|
+
string = "Allgemeiner Gesch\xE4ftspartne".force_encoding("ASCII-8BIT")
|
150
|
+
response.stub(:body).and_return(string)
|
151
|
+
subject.execute
|
152
|
+
|
153
|
+
subject.instance_variable_get(:@raw_response)[:string].encoding.to_s.should eql "UTF-8"
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'yaml'
|
3
|
+
require 'collmex'
|
4
|
+
require "vcr"
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
describe Collmex do
|
9
|
+
it {should respond_to :username}
|
10
|
+
it {should respond_to :password}
|
11
|
+
it {should respond_to :customer_id}
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe "CollmexIntegration" do
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
Collmex.setup_login_data
|
19
|
+
end
|
20
|
+
|
21
|
+
after(:each) do
|
22
|
+
Collmex.reset_login_data
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should work with the long form" do
|
26
|
+
|
27
|
+
request = Collmex::Request.new
|
28
|
+
|
29
|
+
c1 = request.add_command Collmex::Api::CustomerGet.new(customer_id: 9999)
|
30
|
+
c2 = request.add_command Collmex::Api::AccdocGet.new()
|
31
|
+
c3 = request.add_command Collmex::Api::AccdocGet.new(accdoc_id: 1)
|
32
|
+
|
33
|
+
VCR.use_cassette('standard_request') do
|
34
|
+
request.execute
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should work with the block form" do
|
41
|
+
|
42
|
+
# ap Collmex::Api::AccdocGet.new("ASDASD;2;2")
|
43
|
+
|
44
|
+
request = Collmex::Request.run do
|
45
|
+
enqueue :customer_get, id: 9999
|
46
|
+
end
|
47
|
+
|
48
|
+
#ap request.response
|
49
|
+
|
50
|
+
request.response.last.success?.should eql true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require "awesome_print"
|
3
|
+
require "vcr"
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
|
7
|
+
config.color_enabled = true
|
8
|
+
config.filter_run :focus => true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
|
12
|
+
config.before(:each) do
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def timed(name)
|
20
|
+
start = Time.now
|
21
|
+
puts "\n[STARTED: #{name}]"
|
22
|
+
yield if block_given?
|
23
|
+
finish = Time.now
|
24
|
+
puts "[FINISHED: #{name} in #{(finish - start) * 1000} milliseconds]"
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
VCR.configure do |c|
|
29
|
+
c.allow_http_connections_when_no_cassette = true
|
30
|
+
c.cassette_library_dir = 'fixtures/vcr_cassettes'
|
31
|
+
c.hook_into :webmock
|
32
|
+
end
|
33
|
+
|
34
|
+
require "collmex"
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: collmex-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Roman Lehnert
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70139378772860 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.5'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70139378772860
|
25
|
+
description: A lib written in ruby that talks to the german accounting software collmex.
|
26
|
+
email: roman.lehnert@googlemail.com
|
27
|
+
executables: []
|
28
|
+
extensions: []
|
29
|
+
extra_rdoc_files: []
|
30
|
+
files:
|
31
|
+
- lib/collmex/api/line.rb
|
32
|
+
- lib/collmex/api/lines.rb
|
33
|
+
- lib/collmex/api.rb
|
34
|
+
- lib/collmex/request.rb
|
35
|
+
- lib/collmex.rb
|
36
|
+
- spec/lib/collmex/api_spec.rb
|
37
|
+
- spec/lib/collmex/request_spec.rb
|
38
|
+
- spec/lib/collmex_spec.rb
|
39
|
+
- spec/spec_helper.rb
|
40
|
+
homepage: https://github.com/romanlehnert/collmex-ruby
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.10
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: A ruby api lib for collmex
|
64
|
+
test_files:
|
65
|
+
- spec/lib/collmex/api_spec.rb
|
66
|
+
- spec/lib/collmex/request_spec.rb
|
67
|
+
- spec/lib/collmex_spec.rb
|
68
|
+
- spec/spec_helper.rb
|