ifsApi 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5531095024b44363040accb2f4c258bdfd6f7d5449486403d9d3a8991a00c39e
4
+ data.tar.gz: 0eb9859acb620d75f1ed77ead8a95dee7a68ac058209ae2011dcd8948af776da
5
+ SHA512:
6
+ metadata.gz: 8fa3ed83d73d39aee09f0621af13b2583d043cdbe724226e4ba2c51334c7ea2c82d64d26d7cbfb338ae30b4106162a6170a0ee6bc043c3cc900815d2853ff465
7
+ data.tar.gz: f7421c28349f361007f8989234bd15b7d3f264aed4b6d5b3160f77a02aea8cb7dd35c0da539c360fa399d91bc9c80717af02ae912d4ebb12f5a046be7ad4a70f
data/lib/ifsApi.rb ADDED
@@ -0,0 +1,138 @@
1
+ require "rest-client"
2
+ require_relative "IfsHelpers"
3
+ require_relative "IfsApiException"
4
+ require_relative "IfsApiResponse"
5
+ require "json"
6
+
7
+ module IFS
8
+ class Api
9
+ @userid = ""
10
+ @password = ""
11
+ @role = ""
12
+ attr_accessor :isProduction
13
+
14
+ def initialize(userid, password, role)
15
+ @userid = userid
16
+ @password = password
17
+ @role = role
18
+ @isProduction = false
19
+ end
20
+
21
+ def put_order_sku(id, itemNumber, vendorSku)
22
+ url = endpoint "ordersku", id
23
+ url += "?itemNumber=#{itemNumber}&vendorSku=#{vendorSku}"
24
+ put url
25
+ end
26
+
27
+ def get_order(id)
28
+ url = endpoint "order", id
29
+ get url
30
+ end
31
+
32
+ def get_orders(args = {})
33
+ url = endpoint "orders"
34
+ get url, args
35
+ end
36
+
37
+ def get_web_artwork_transaction_id(id)
38
+ url = endpoint "webartworktransaction", id
39
+ get url
40
+ end
41
+
42
+ def get_web_artwork_transaction(args)
43
+ url = endpoint "webartworktransaction"
44
+ get url, args
45
+ end
46
+
47
+ def post_custom_order(args)
48
+ url = endpoint "customorder"
49
+ post url, args
50
+ end
51
+
52
+ def post_order_body(args)
53
+ url = endpoint "orderbody"
54
+ post url, args
55
+ end
56
+
57
+ def put_order_body(args)
58
+ url = endpoint "orderbody"
59
+ put url, args
60
+ end
61
+
62
+ def get_order_status(id)
63
+ url = endpoint "orderstatus", id
64
+ get url
65
+ end
66
+
67
+ def put_order_status(id, itemNumber, status)
68
+ url = endpoint "orderstatus", id
69
+ url += "?itemNumber=#{itemNumber}&status=#{status}"
70
+ put url, {}
71
+ end
72
+
73
+ #PRIVATE
74
+ private
75
+
76
+ def baseUrl
77
+ r = "https://nwframing.com/"
78
+ if isProduction
79
+ r = "#{r}ifs"
80
+ else
81
+ r = "#{r}ifs.test"
82
+ end
83
+ "#{r}/api/#{@role}"
84
+ end
85
+
86
+ def endpoint(action, id = nil)
87
+ r = "#{baseUrl}/#{action}"
88
+ unless id.nil?
89
+ r = "#{r}/#{id}"
90
+ end
91
+ r
92
+ end
93
+
94
+ def get(url, params = {})
95
+ header = basicHeader
96
+ header[:params] = params
97
+ begin
98
+ r = RestClient.get url, header
99
+ IFS::ApiResponse.new(r.code, r.body)
100
+ rescue RestClient::ExceptionWithResponse => e
101
+ x = JSON.parse(e.response)
102
+ raise IFSApiException.new(x["errorDescription"], e, x["errorDetails"])
103
+ end
104
+ end
105
+
106
+ def post(url, payload = {})
107
+ begin
108
+ header = basicHeader
109
+ header["Content-Type"] = "application/json"
110
+ r = RestClient.post url, payload.to_json, header
111
+ IFS::ApiResponse.new(r.code, r.body)
112
+ rescue RestClient::ExceptionWithResponse => e
113
+ x = JSON.parse(e.response)
114
+ raise IFSApiException.new(x["errorDescription"], e, x["errorDetails"])
115
+ end
116
+ end
117
+
118
+ def put(url, payload = {})
119
+ begin
120
+ header = basicHeader
121
+ header["Content-Type"] = "application/json"
122
+ r = RestClient.put url, payload.to_json, header
123
+ IFS::ApiResponse.new(r.code, r.body)
124
+ rescue RestClient::ExceptionWithResponse => e
125
+ x = JSON.parse(e.response)
126
+ raise IFSApiException.new(x["errorDescription"], e, x["errorDetails"])
127
+ end
128
+ end
129
+
130
+ def basicHeader
131
+ {:Authorization => authString, :Accept => "application/json"}
132
+ end
133
+
134
+ def authString
135
+ IFS::Helper::authString @userid, @password
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,10 @@
1
+ class IFSApiException < StandardError
2
+ attr_reader :code
3
+ attr_reader :detail
4
+
5
+ def initialize(message, code, detail)
6
+ super(message)
7
+ @code = code
8
+ @detail = detail
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ require "json"
2
+
3
+ module IFS
4
+ class ApiResponse
5
+ attr_accessor :body
6
+ attr_accessor :code
7
+
8
+ def initialize(code, body)
9
+ @code = code
10
+ @body = body
11
+ end
12
+
13
+ def parse
14
+ JSON.parse(@body)
15
+ end
16
+ end
17
+ end
data/lib/ifsHelpers.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "base64"
2
+
3
+ module IFS
4
+ class Helper
5
+ class << self
6
+ def authString(userid, password)
7
+ combo = "#{userid}:#{password}"
8
+ "Basic #{Base64::encode64(combo)}"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module IFSOrderStatus
3
+ HOLD = 1
4
+ RESUME = 1
5
+ CANCEL = 2
6
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ifsApi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Jones
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Access IFS Api
14
+ email: justinj@nwframing.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/ifsApi.rb
20
+ - lib/ifsApiException.rb
21
+ - lib/ifsApiResponse.rb
22
+ - lib/ifsHelpers.rb
23
+ - lib/ifsOrderStatus.rb
24
+ homepage:
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.7.6
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: ''
48
+ test_files: []