clearsale 0.1.0
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.
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +98 -0
- data/Guardfile +10 -0
- data/README.rdoc +107 -0
- data/Rakefile +6 -0
- data/clearsale.gemspec +34 -0
- data/lib/clearsale.rb +11 -0
- data/lib/clearsale/analysis.rb +27 -0
- data/lib/clearsale/connector.rb +63 -0
- data/lib/clearsale/object.rb +27 -0
- data/lib/clearsale/order.rb +122 -0
- data/lib/clearsale/order_response.rb +53 -0
- data/lib/clearsale/version.rb +3 -0
- data/spec/fixtures/vcr_cassettes/clearsale_get_order_status.yml +59 -0
- data/spec/fixtures/vcr_cassettes/clearsale_get_order_status_missing.yml +58 -0
- data/spec/fixtures/vcr_cassettes/clearsale_get_order_status_production.yml +60 -0
- data/spec/fixtures/vcr_cassettes/clearsale_send_orders.yml +76 -0
- data/spec/object_spec.rb +82 -0
- data/spec/order_response_spec.rb +27 -0
- data/spec/order_spec.rb +17 -0
- data/spec/requests/clearsale_spec.rb +68 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/helpers.rb +81 -0
- metadata +289 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Clearsale
|
|
2
|
+
class OrderResponse
|
|
3
|
+
STATUS_MAP = {
|
|
4
|
+
"APA" => :automatic_approval,
|
|
5
|
+
"APM" => :manual_approval,
|
|
6
|
+
"RPM" => :rejected_without_suspicion,
|
|
7
|
+
"AMA" => :manual_analysis,
|
|
8
|
+
"ERR" => :error,
|
|
9
|
+
"NVO" => :waiting,
|
|
10
|
+
"SUS" => :manual_rejection,
|
|
11
|
+
"CAN" => :cancelled,
|
|
12
|
+
"FRD" => :fraud,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
attr_reader :order_id, :status, :score
|
|
16
|
+
|
|
17
|
+
def self.build_from_send_order(package)
|
|
18
|
+
new(package.fetch(:package_status, {}))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.build_from_update(package)
|
|
22
|
+
new(package.fetch(:clear_sale, {}))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def initialize(hash)
|
|
26
|
+
response = hash.fetch(:orders, {}).fetch(:order, {})
|
|
27
|
+
|
|
28
|
+
if response.blank?
|
|
29
|
+
@status = :inexistent_order
|
|
30
|
+
else
|
|
31
|
+
@order_id = response[:id].gsub(/[a-zA-Z]*/, '').to_i
|
|
32
|
+
@score = response[:score].to_f
|
|
33
|
+
@status = STATUS_MAP[response[:status]]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def approved?
|
|
38
|
+
@status == :automatic_approval || @status == :manual_approval
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def rejected?
|
|
42
|
+
@status == :rejected_without_suspicion || @status == :fraud || @status == :manual_rejection
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def manual_analysis?
|
|
46
|
+
@status == :manual_analysis
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def inexistent_order?
|
|
50
|
+
@status == :inexistent_order
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
|
3
|
+
request: !ruby/struct:VCR::Request
|
|
4
|
+
method: :post
|
|
5
|
+
uri: http://homologacao.clearsale.com.br:80/Integracaov2/Service.asmx
|
|
6
|
+
body: <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
|
7
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.clearsale.com.br/integration"
|
|
8
|
+
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><int:GetOrderStatus><int:orderID>TS1234</int:orderID><int:entityCode>0E6F0C82-FC05-4AA7-86D4-EBBFC0FDC41A</int:entityCode></int:GetOrderStatus></soap:Body></soap:Envelope>
|
|
9
|
+
headers:
|
|
10
|
+
soapaction:
|
|
11
|
+
- http://www.clearsale.com.br/integration/GetOrderStatus
|
|
12
|
+
content-type:
|
|
13
|
+
- text/xml;charset=UTF-8
|
|
14
|
+
content-length:
|
|
15
|
+
- '439'
|
|
16
|
+
response: !ruby/struct:VCR::Response
|
|
17
|
+
status: !ruby/struct:VCR::ResponseStatus
|
|
18
|
+
code: 200
|
|
19
|
+
message: !binary |-
|
|
20
|
+
T0s=
|
|
21
|
+
headers:
|
|
22
|
+
!binary "ZGF0ZQ==":
|
|
23
|
+
- !binary |-
|
|
24
|
+
V2VkLCAxMSBBcHIgMjAxMiAyMDozODowMCBHTVQ=
|
|
25
|
+
!binary "c2VydmVy":
|
|
26
|
+
- !binary |-
|
|
27
|
+
TWljcm9zb2Z0LUlJUy82LjA=
|
|
28
|
+
!binary "eC1wb3dlcmVkLWJ5":
|
|
29
|
+
- !binary |-
|
|
30
|
+
QVNQLk5FVA==
|
|
31
|
+
!binary "eC1hc3BuZXQtdmVyc2lvbg==":
|
|
32
|
+
- !binary |-
|
|
33
|
+
Mi4wLjUwNzI3
|
|
34
|
+
!binary "Y2FjaGUtY29udHJvbA==":
|
|
35
|
+
- !binary |-
|
|
36
|
+
cHJpdmF0ZSwgbWF4LWFnZT0w
|
|
37
|
+
!binary "Y29udGVudC10eXBl":
|
|
38
|
+
- !binary |-
|
|
39
|
+
YXBwbGljYXRpb24vc29hcCt4bWw7IGNoYXJzZXQ9dXRmLTg=
|
|
40
|
+
!binary "Y29udGVudC1sZW5ndGg=":
|
|
41
|
+
- !binary |-
|
|
42
|
+
NjYz
|
|
43
|
+
body: !binary |-
|
|
44
|
+
PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c29hcDpF
|
|
45
|
+
bnZlbG9wZSB4bWxuczpzb2FwPSJodHRwOi8vd3d3LnczLm9y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Request
|
|
4
|
+
method: :post
|
|
5
|
+
uri: http://homologacao.clearsale.com.br:80/Integracaov2/Service.asmx
|
|
6
|
+
body: <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
|
7
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.clearsale.com.br/integration"
|
|
8
|
+
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><int:GetOrderStatus><int:orderID>1234567890</int:orderID><int:entityCode>0E6F0C82-FC05-4AA7-86D4-EBBFC0FDC41A</int:entityCode></int:GetOrderStatus></soap:Body></soap:Envelope>
|
|
9
|
+
headers:
|
|
10
|
+
soapaction:
|
|
11
|
+
- http://www.clearsale.com.br/integration/GetOrderStatus
|
|
12
|
+
content-type:
|
|
13
|
+
- text/xml;charset=UTF-8
|
|
14
|
+
content-length:
|
|
15
|
+
- '443'
|
|
16
|
+
response: !ruby/struct:VCR::Response
|
|
17
|
+
status: !ruby/struct:VCR::ResponseStatus
|
|
18
|
+
code: 200
|
|
19
|
+
message: !binary |-
|
|
20
|
+
T0s=
|
|
21
|
+
headers:
|
|
22
|
+
!binary "ZGF0ZQ==":
|
|
23
|
+
- !binary |-
|
|
24
|
+
TW9uLCAwOSBBcHIgMjAxMiAxOToxMjoyNyBHTVQ=
|
|
25
|
+
!binary "c2VydmVy":
|
|
26
|
+
- !binary |-
|
|
27
|
+
TWljcm9zb2Z0LUlJUy82LjA=
|
|
28
|
+
!binary "eC1wb3dlcmVkLWJ5":
|
|
29
|
+
- !binary |-
|
|
30
|
+
QVNQLk5FVA==
|
|
31
|
+
!binary "eC1hc3BuZXQtdmVyc2lvbg==":
|
|
32
|
+
- !binary |-
|
|
33
|
+
Mi4wLjUwNzI3
|
|
34
|
+
!binary "Y2FjaGUtY29udHJvbA==":
|
|
35
|
+
- !binary |-
|
|
36
|
+
cHJpdmF0ZSwgbWF4LWFnZT0w
|
|
37
|
+
!binary "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C9HZXRPcmRlclN0YXR1c1Jlc3BvbnNlPjwvc29hcDpCb2R5Pjwv
|
|
57
|
+
c29hcDpFbnZlbG9wZT4=
|
|
58
|
+
http_version: '1.1'
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
|
3
|
+
request: !ruby/struct:VCR::Request
|
|
4
|
+
method: :post
|
|
5
|
+
uri: https://www.clearsale.com.br/integracaov2/service.asmx
|
|
6
|
+
body: <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
|
7
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.clearsale.com.br/integration"
|
|
8
|
+
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><int:GetOrderStatus><int:orderID>TS1234</int:orderID><int:entityCode>0E6F0C82-FC05-4AA7-86D4-EBBFC0FDC41A</int:entityCode></int:GetOrderStatus></soap:Body></soap:Envelope>
|
|
9
|
+
headers:
|
|
10
|
+
soapaction:
|
|
11
|
+
- http://www.clearsale.com.br/integration/GetOrderStatus
|
|
12
|
+
content-type:
|
|
13
|
+
- text/xml;charset=UTF-8
|
|
14
|
+
content-length:
|
|
15
|
+
- '439'
|
|
16
|
+
response: !ruby/struct:VCR::Response
|
|
17
|
+
status: !ruby/struct:VCR::ResponseStatus
|
|
18
|
+
code: 200
|
|
19
|
+
message: !binary |-
|
|
20
|
+
T0s=
|
|
21
|
+
headers:
|
|
22
|
+
!binary "ZGF0ZQ==":
|
|
23
|
+
- !binary |-
|
|
24
|
+
V2VkLCAxMSBBcHIgMjAxMiAyMDozODowMCBHTVQ=
|
|
25
|
+
!binary "c2VydmVy":
|
|
26
|
+
- !binary |-
|
|
27
|
+
TWljcm9zb2Z0LUlJUy82LjA=
|
|
28
|
+
!binary "eC1wb3dlcmVkLWJ5":
|
|
29
|
+
- !binary |-
|
|
30
|
+
QVNQLk5FVA==
|
|
31
|
+
!binary "eC1hc3BuZXQtdmVyc2lvbg==":
|
|
32
|
+
- !binary |-
|
|
33
|
+
Mi4wLjUwNzI3
|
|
34
|
+
!binary "Y2FjaGUtY29udHJvbA==":
|
|
35
|
+
- !binary |-
|
|
36
|
+
cHJpdmF0ZSwgbWF4LWFnZT0w
|
|
37
|
+
!binary "Y29udGVudC10eXBl":
|
|
38
|
+
- !binary |-
|
|
39
|
+
YXBwbGljYXRpb24vc29hcCt4bWw7IGNoYXJzZXQ9dXRmLTg=
|
|
40
|
+
!binary "Y29udGVudC1sZW5ndGg=":
|
|
41
|
+
- !binary |-
|
|
42
|
+
NjYz
|
|
43
|
+
body: !binary |-
|
|
44
|
+
PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c29hcDpF
|
|
45
|
+
bnZlbG9wZSB4bWxuczpzb2FwPSJodHRwOi8vd3d3LnczLm9yZy8yMDAzLzA1
|
|
46
|
+
L3NvYXAtZW52ZWxvcGUiIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcv
|
|
47
|
+
MjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIHhtbG5zOnhzZD0iaHR0cDovL3d3
|
|
48
|
+
dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiPjxzb2FwOkJvZHk+PEdldE9yZGVy
|
|
49
|
+
U3RhdHVzUmVzcG9uc2UgeG1sbnM9Imh0dHA6Ly93d3cuY2xlYXJzYWxlLmNv
|
|
50
|
+
bS5ici9pbnRlZ3JhdGlvbiI+PEdldE9yZGVyU3RhdHVzUmVzdWx0PiZsdDs/
|
|
51
|
+
eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9InV0Zi0xNiI/Jmd0Ow0KJmx0
|
|
52
|
+
O0NsZWFyU2FsZSZndDsNCiAgJmx0O09yZGVycyZndDsNCiAgICAmbHQ7T3Jk
|
|
53
|
+
ZXImZ3Q7DQogICAgICAmbHQ7SUQmZ3Q7VFMxMjM0Jmx0Oy9JRCZndDsNCiAg
|
|
54
|
+
ICAgICZsdDtTdGF0dXMmZ3Q7QU1BJmx0Oy9TdGF0dXMmZ3Q7DQogICAgICAm
|
|
55
|
+
bHQ7U2NvcmUmZ3Q7MjEuMTEwMCZsdDsvU2NvcmUmZ3Q7DQogICAgJmx0Oy9P
|
|
56
|
+
cmRlciZndDsNCiAgJmx0Oy9PcmRlcnMmZ3Q7DQombHQ7L0NsZWFyU2FsZSZn
|
|
57
|
+
dDs8L0dldE9yZGVyU3RhdHVzUmVzdWx0PjwvR2V0T3JkZXJTdGF0dXNSZXNw
|
|
58
|
+
b25zZT48L3NvYXA6Qm9keT48L3NvYXA6RW52ZWxvcGU+
|
|
59
|
+
http_version: '1.1'
|
|
60
|
+
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
|
3
|
+
request: !ruby/struct:VCR::Request
|
|
4
|
+
method: :post
|
|
5
|
+
uri: http://homologacao.clearsale.com.br:80/Integracaov2/Service.asmx
|
|
6
|
+
body: <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
|
7
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.clearsale.com.br/integration"
|
|
8
|
+
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><int:SendOrders><int:xml><ClearSale><Orders><Order><ID>TS1234</ID><Date>2012-04-11T20:36:11</Date><Email>petergriffin@abc.com</Email><TotalItens>25.0</TotalItens><TotalOrder>20.0</TotalOrder><QtyInstallments>3</QtyInstallments><QtyItems>3</QtyItems><IP>127.0.0.1</IP><CollectionData><ID>8888</ID><Type>1</Type><LegalDocument1>24878346337</LegalDocument1><Name>Peter
|
|
9
|
+
Löwenbräu Griffin</Name><BirthDate>1972-04-11T20:36:11</BirthDate><Email>petergriffin@abc.com</Email><Genre>m</Genre><Address><Street>Bla
|
|
10
|
+
St</Street><Number>123</Number><Comp></Comp><County>Rhode
|
|
11
|
+
Island</County><City>Mayland</City><State>Maryland</State><ZipCode>00100-011</ZipCode></Address><Phones><Phone><Type>0</Type><DDD>11</DDD><Number>80011002</Number></Phone></Phones></CollectionData><ShippingData><ID>8888</ID><Type>1</Type><LegalDocument1>24878346337</LegalDocument1><Name>Peter
|
|
12
|
+
Löwenbräu Griffin</Name><BirthDate>1972-04-11T20:36:11</BirthDate><Email>petergriffin@abc.com</Email><Genre>m</Genre><Address><Street>Bla
|
|
13
|
+
St</Street><Number>123</Number><Comp></Comp><County>Rhode
|
|
14
|
+
Island</County><City>Mayland</City><State>Maryland</State><ZipCode>00100-011</ZipCode></Address><Phones><Phone><Type>0</Type><DDD>11</DDD><Number>80011002</Number></Phone></Phones></ShippingData><Payments><Payment><Date>2012-04-11T20:36:09</Date><Amount>20.0</Amount><PaymentTypeID>1</PaymentTypeID><QtyInstallments>3</QtyInstallments><CardNumber>2222</CardNumber><CardBin>1234432</CardBin><CardType>3</CardType><CardExpirationDate>05/2012</CardExpirationDate><Name>Peter
|
|
15
|
+
Löwenbräu Griffin</Name><LegalDocument>24878346337</LegalDocument><Address><Street>Bla
|
|
16
|
+
St</Street><Number>123</Number><Comp></Comp><County>Rhode
|
|
17
|
+
Island</County><City>Mayland</City><State>Maryland</State><ZipCode>00100-011</ZipCode></Address></Payment></Payments><Items><Item><ID>5555</ID><Name>Pogobol</Name><ItemValue>5.0</ItemValue><Qty>2</Qty><CategoryID>7777</CategoryID><CategoryName>Disney</CategoryName></Item><Item><ID>5555</ID><Name>Pogobol</Name><ItemValue>5.0</ItemValue><Qty>2</Qty><CategoryID>7777</CategoryID><CategoryName>Disney</CategoryName></Item></Items></Order></Orders></ClearSale></int:xml><int:entityCode>0E6F0C82-FC05-4AA7-86D4-EBBFC0FDC41A</int:entityCode></int:SendOrders></soap:Body></soap:Envelope>
|
|
18
|
+
headers:
|
|
19
|
+
soapaction:
|
|
20
|
+
- http://www.clearsale.com.br/integration/SendOrders
|
|
21
|
+
content-type:
|
|
22
|
+
- text/xml;charset=UTF-8
|
|
23
|
+
content-length:
|
|
24
|
+
- '3580'
|
|
25
|
+
response: !ruby/struct:VCR::Response
|
|
26
|
+
status: !ruby/struct:VCR::ResponseStatus
|
|
27
|
+
code: 200
|
|
28
|
+
message: !binary |-
|
|
29
|
+
T0s=
|
|
30
|
+
headers:
|
|
31
|
+
!binary "ZGF0ZQ==":
|
|
32
|
+
- !binary |-
|
|
33
|
+
V2VkLCAxMSBBcHIgMjAxMiAyMDozNjoxNSBHTVQ=
|
|
34
|
+
!binary "c2VydmVy":
|
|
35
|
+
- !binary |-
|
|
36
|
+
TWljcm9zb2Z0LUlJUy82LjA=
|
|
37
|
+
!binary "eC1wb3dlcmVkLWJ5":
|
|
38
|
+
- !binary |-
|
|
39
|
+
QVNQLk5FVA==
|
|
40
|
+
!binary "eC1hc3BuZXQtdmVyc2lvbg==":
|
|
41
|
+
- !binary |-
|
|
42
|
+
Mi4wLjUwNzI3
|
|
43
|
+
!binary "c2V0LWNvb2tpZQ==":
|
|
44
|
+
- !binary |-
|
|
45
|
+
QVNQLk5FVF9TZXNzaW9uSWQ9aXkyNG4wNTV1NXVrM3hpMDJtZ3Bwd25sOyBw
|
|
46
|
+
YXRoPS87IEh0dHBPbmx5
|
|
47
|
+
!binary "Y2FjaGUtY29udHJvbA==":
|
|
48
|
+
- !binary |-
|
|
49
|
+
cHJpdmF0ZSwgbWF4LWFnZT0w
|
|
50
|
+
!binary "Y29udGVudC10eXBl":
|
|
51
|
+
- !binary |-
|
|
52
|
+
YXBwbGljYXRpb24vc29hcCt4bWw7IGNoYXJzZXQ9dXRmLTg=
|
|
53
|
+
!binary "Y29udGVudC1sZW5ndGg=":
|
|
54
|
+
- !binary |-
|
|
55
|
+
ODE4
|
|
56
|
+
body: !binary |-
|
|
57
|
+
PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c29hcDpF
|
|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9PcmRlciZndDsNCiAgJmx0Oy9PcmRl
|
|
73
|
+
cnMmZ3Q7DQombHQ7L1BhY2thZ2VTdGF0dXMmZ3Q7PC9TZW5kT3JkZXJzUmVz
|
|
74
|
+
dWx0PjwvU2VuZE9yZGVyc1Jlc3BvbnNlPjwvc29hcDpCb2R5Pjwvc29hcDpF
|
|
75
|
+
bnZlbG9wZT4=
|
|
76
|
+
http_version: '1.1'
|
data/spec/object_spec.rb
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Clearsale
|
|
4
|
+
describe Object do
|
|
5
|
+
describe "behavior it inherits from OpenStruct" do
|
|
6
|
+
it "can represent arbitrary data objects" do
|
|
7
|
+
ros = Object.new
|
|
8
|
+
ros.blah = "John Smith"
|
|
9
|
+
ros.blah.should == "John Smith"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "can be created from a hash" do
|
|
13
|
+
h = { :asdf => 'John Smith' }
|
|
14
|
+
ros = Object.new(h)
|
|
15
|
+
ros.asdf.should == "John Smith"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "can modify an existing key" do
|
|
19
|
+
h = { :blah => 'John Smith' }
|
|
20
|
+
ros = Object.new(h)
|
|
21
|
+
ros.blah = "George Washington"
|
|
22
|
+
ros.blah.should == "George Washington"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "handling of arbitrary attributes" do
|
|
26
|
+
before(:each) do
|
|
27
|
+
@object = Object.new
|
|
28
|
+
@object.blah = "John Smith"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe "#respond?" do
|
|
32
|
+
it { @object.should respond_to :blah }
|
|
33
|
+
it { @object.should respond_to :blah= }
|
|
34
|
+
it { @object.should_not respond_to :asdf }
|
|
35
|
+
it { @object.should_not respond_to :asdf= }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "#methods" do
|
|
39
|
+
it { @object.methods.should include :blah }
|
|
40
|
+
it { @object.methods.should include :blah= }
|
|
41
|
+
it { @object.methods.should_not include :asdf }
|
|
42
|
+
it { @object.methods.should_not include :asdf= }
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe "recursive behavior" do
|
|
48
|
+
before(:each) do
|
|
49
|
+
h = { :blah => { :another => 'value'}, :list => [ { :foo => :bar } ] }
|
|
50
|
+
@object = Object.new(h)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "returns accessed hashes as Objects instead of hashes" do
|
|
54
|
+
@object.blah.another.should == 'value'
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "uses #key_as_a_hash to return key as a Hash" do
|
|
58
|
+
@object.blah_as_a_hash.should == { :another => 'value' }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "return access hash as Object instead of hash even if it is inside a list" do
|
|
62
|
+
@object.list.first.foo.should == :bar
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe "handling loops in the origin Hashes" do
|
|
66
|
+
before(:each) do
|
|
67
|
+
h1 = { :a => 'a'}
|
|
68
|
+
h2 = { :a => 'b', :h1 => h1 }
|
|
69
|
+
h1[:h2] = h2
|
|
70
|
+
@object = Object.new(h2)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it { @object.h1.a.should == 'a' }
|
|
74
|
+
it { @object.h1.h2.a.should == 'b' }
|
|
75
|
+
it { @object.h1.h2.h1.a.should == 'a' }
|
|
76
|
+
it { @object.h1.h2.h1.h2.a.should == 'b' }
|
|
77
|
+
it { @object.h1.should == @object.h1.h2.h1 }
|
|
78
|
+
it { @object.h1.should_not == @object.h1.h2 }
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Clearsale
|
|
4
|
+
describe OrderResponse do
|
|
5
|
+
describe "#approved?" do
|
|
6
|
+
let(:response) { {:orders=>{:order=>{:id=>"TS1234", :score=>"21.1100"}}} }
|
|
7
|
+
|
|
8
|
+
%w(APA APM).each do |status|
|
|
9
|
+
it "should return true if status return is: #{status}" do
|
|
10
|
+
response[:orders][:order][:status] = status
|
|
11
|
+
OrderResponse.new(response).should be_approved
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "#rejected?" do
|
|
17
|
+
let(:response) { {:orders=>{:order=>{:id=>"TS1234", :score=>"21.1100"}}} }
|
|
18
|
+
|
|
19
|
+
%w(RPM FRD SUS).each do |status|
|
|
20
|
+
it "should return true if status return is: #{status}" do
|
|
21
|
+
response[:orders][:order][:status] = status
|
|
22
|
+
OrderResponse.new(response).should be_rejected
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/spec/order_spec.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
require 'timecop'
|
|
4
|
+
|
|
5
|
+
module Clearsale
|
|
6
|
+
describe Order do
|
|
7
|
+
describe ".to_xml" do
|
|
8
|
+
it "converts the order to xml successfully" do
|
|
9
|
+
Timecop.freeze Time.parse('2012-07-01 11:13')
|
|
10
|
+
_order = Object.new(order)
|
|
11
|
+
_payment = Object.new(payment)
|
|
12
|
+
_user = Object.new(user)
|
|
13
|
+
described_class.to_xml(_order, _payment, _user).should eq '<ClearSale><Orders><Order><ID>1234</ID><Date>2012-07-01T11:13:00</Date><Email>petergriffin@abc.com</Email><TotalItens>20.0</TotalItens><TotalOrder>25.0</TotalOrder><QtyInstallments>3</QtyInstallments><QtyItems>3</QtyItems><IP>127.0.0.1</IP><CollectionData><ID>8888</ID><Type>1</Type><LegalDocument1>24878346337</LegalDocument1><Name>Peter Löwenbräu Griffin</Name><BirthDate>1972-07-01T11:13:00</BirthDate><Email>petergriffin@abc.com</Email><Genre>m</Genre><Address><Street>Billing Street</Street><Number>123</Number><Comp></Comp><County>Rhode Island</County><City>Mayland</City><State>Maryland</State><ZipCode>00100-011</ZipCode></Address><Phones><Phone><Type>0</Type><DDD>11</DDD><Number>80011002</Number></Phone></Phones></CollectionData><ShippingData><ID>8888</ID><Type>1</Type><LegalDocument1>24878346337</LegalDocument1><Name>Peter Löwenbräu Griffin</Name><BirthDate>1972-07-01T11:13:00</BirthDate><Email>petergriffin@abc.com</Email><Genre>m</Genre><Address><Street>Shipping Street</Street><Number>123</Number><Comp></Comp><County>Rhode Island</County><City>Mayland</City><State>Maryland</State><ZipCode>00100-011</ZipCode></Address><Phones><Phone><Type>0</Type><DDD>11</DDD><Number>80011002</Number></Phone></Phones></ShippingData><Payments><Payment><Date>2012-07-01T11:12:58</Date><Amount>50.0</Amount><PaymentTypeID>1</PaymentTypeID><QtyInstallments>3</QtyInstallments><CardNumber>1234432111112222</CardNumber><CardBin>123443</CardBin><CardType>4</CardType><CardExpirationDate>05/2012</CardExpirationDate><Name></Name><LegalDocument>24878346337</LegalDocument><Address><Street>Billing Street</Street><Number>123</Number><Comp></Comp><County>Rhode Island</County><City>Mayland</City><State>Maryland</State><ZipCode>00100-011</ZipCode></Address></Payment></Payments><Items><Item><ID>5555</ID><Name>Pogobol</Name><ItemValue>5.0</ItemValue><Qty>2</Qty><CategoryID>7777</CategoryID><CategoryName>Disney</CategoryName></Item><Item><ID>5555</ID><Name>Pogobol</Name><ItemValue>5.0</ItemValue><Qty>2</Qty><CategoryID>7777</CategoryID><CategoryName>Disney</CategoryName></Item></Items></Order></Orders></ClearSale>'
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|