BPRubySDK 0.0.5

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dbbd9b032ebe63a187772981b88fc29a80d33554
4
+ data.tar.gz: aa802ba911e999bfeccc1c23721756ba6418de78
5
+ SHA512:
6
+ metadata.gz: 242447c1a161f6d3efee222053ac144535a8e44d2dcf5d3d345dce62739b622ec50276b18447c2faae7d64c9b8362c0e97501e7e507ae90738f0e6ad5403c881
7
+ data.tar.gz: cf74ea47bfb97fcad4f280649c6da0781620f237e8b95afd3ce81ef8f6f37e79141251474542bd742974b2ed3629c749630383cdaeba6527d7c5ee2799819f80
@@ -0,0 +1,5 @@
1
+ require "BPRubySDK/version"
2
+ require 'handlers/request_method_handler'
3
+ module BPRubySDK
4
+ #Todo
5
+ end
@@ -0,0 +1,3 @@
1
+ module BPRubySDK
2
+ VERSION = "0.0.5"
3
+ end
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ =begin
3
+ Used to create a connection to the Brightpearl API via Ruby
4
+ =end
5
+ class Connection
6
+
7
+ attr_reader :appRef
8
+ attr_reader :appToken
9
+ attr_reader :dataCenter
10
+ attr_reader :apiVersion
11
+ attr_reader :accountID
12
+
13
+ def initialize(appRef,appToken,accID,dataCenter,apiVersion = "public-api")
14
+ @appRef = appRef
15
+ @appToken = appToken
16
+ @accountID = accID
17
+ @apiVersion = apiVersion
18
+
19
+ #checking if passed in datacenter is correct value, and stripping it of any format (camel case or similar)
20
+ @dataCenter = dataCenter.downcase if dataCenter.casecmp("use") || dataCenter.casecmp("eu1")
21
+ @dataCenter = "eu1" if dataCenter.casecmp("euw") == dataCenter
22
+ end
23
+ #end init
24
+
25
+ #checks auth against warehouse service
26
+ public
27
+ def checkAuthorization
28
+ puts 'http://ws-' << @dataCenter<< '.brightpearl.com/' << @apiVersion <<'/' << @accountID << '/warehouse-service/warehouse'
29
+ uri = URI('http://ws-' << @dataCenter<< '.brightpearl.com/' << @apiVersion <<'/' << @accountID << '/warehouse-service/warehouse')
30
+ response = Net::HTTP.start(uri.host,uri.port) do |http|
31
+ request = Net::HTTP::Get.new uri
32
+ request.add_field('brightpearl-app-ref',@appRef)
33
+ request.add_field('brightpearl-account-token',@appToken)
34
+
35
+ if @apiVersion.casecmp("use") || @apiVersion.casecmp("eu1")
36
+ http.request request
37
+ else
38
+ puts "Error - Invalid datacenter supplied, please enter a valid datacenter."
39
+ end
40
+ end
41
+ puts "Authorization sucuessful!"
42
+ end
43
+ end
@@ -0,0 +1,20 @@
1
+ #Container class used to store a ready to send request while adding to the request queue.
2
+ class Request
3
+
4
+ attr_reader :id
5
+ attr_reader :uri
6
+ attr_reader :accountID
7
+ attr_accessor :requestType
8
+ attr_accessor :requestBody
9
+ attr_accessor :response
10
+ attr_accessor :httpCode
11
+
12
+ public
13
+ def initialize(id,uri,requestType,accountID,requestBody = nil)
14
+ @id = id
15
+ @uri = uri
16
+ @requestType = requestType
17
+ @accountID = accountID
18
+ @requestBody = requestBody
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ #The Request Method class is a class used to hold data pulled from http://api-docs.brightpearl.com/json-index.html
2
+ class RequestMethod
3
+ attr_reader :name
4
+ attr_reader :service
5
+ attr_reader :resource
6
+ attr_reader :HTTPMethod
7
+ attr_reader :uri
8
+ attr_reader :responses
9
+ attr_reader :apiDomain
10
+ attr_reader :urls
11
+ attr_reader :authorizeServer
12
+ attr_reader :authorizeInstance
13
+ attr_reader :requests
14
+
15
+ public
16
+ def initialize(name,service,resource,httpMethod,uri,responses,apiDomain,urls,authorizeServer,authorizeInstance,requests)
17
+ @name = name
18
+ @service = service
19
+ @resource = resource
20
+ @HTTPMethod = httpMethod
21
+ @uri = uri
22
+ @responses = responses
23
+ @apiDomain = apiDomain
24
+ @urls = urls
25
+ @authorizeServer = authorizeServer
26
+ @authorizeInstance = authorizeInstance
27
+ @requests = requests
28
+ end
29
+
30
+
31
+
32
+ end
@@ -0,0 +1,30 @@
1
+ class Response
2
+ attr_reader :body
3
+ attr_reader :code
4
+ attr_reader :msg
5
+ attr_reader :request
6
+
7
+ public
8
+ def initialize(request,response)
9
+ @request = request
10
+ @body = response.body
11
+ @code = response.code
12
+ @msg = response.msg
13
+ end
14
+
15
+ public
16
+ def getRequestID
17
+ return @request.id
18
+ end
19
+
20
+ public
21
+ def getRequestURI
22
+ return @request.uri
23
+ end
24
+
25
+ public
26
+ def getPostBody
27
+ return @request.requestBody if @request.requestType.to_s.casecmp('post')
28
+ return "This is not a post method."
29
+ end
30
+ end
@@ -0,0 +1,169 @@
1
+ require 'json'
2
+ require 'open-uri' #TODO- Remove this, look into replacing with Net::HTTPResponse read_body
3
+ require 'uri'
4
+ require "appLib/request"
5
+ require "appLib/request_method"
6
+ require "appLib/connection"
7
+ =begin
8
+ This class is used to handle and send requests via the Brightpearl API. It then takes the responses and adds them to the queue, and logs if necessary
9
+ TODO - Current Brightpearl Bugged issues include
10
+ TODO - Api Documentation XML has duplicate parameters in some URLs
11
+ TODO - Warehouse Location PUT having duplicate {ID} tag
12
+ TODO - Warehouse Goods-Out Note Delete having duplicate {ID} tag
13
+ TODO - Warehouse Goods note GET having duplicate {ID-SET}
14
+ TODO - Product Type Association XML POST URI malformed
15
+ TODO - Parameters need standardized
16
+ TODO - API Documentation contains invalid URIs for Developer URIs
17
+ ---------------------------------------------------------------------------
18
+ =end
19
+ class RequestHandler
20
+ attr_reader :responseQueue
21
+ attr_reader :currentConnection
22
+ attr_reader :requestIncrementID
23
+
24
+ public
25
+ def initialize(appRef,appToken,accID,dataCenter,apiVersion)
26
+ @currentConnection = Connection.new(appRef,appToken,accID,dataCenter,apiVersion)
27
+ @requestQueue = Queue.new
28
+ @responseQueue = Queue.new
29
+ @requestIncrementID = 0
30
+ end
31
+
32
+
33
+ #Calls the Brightpearl API with passed in URI, or with a generated URI if a tailing URI is passed in (See documentation)
34
+ #Accepts parameter array, paremeterArray[0] is the first parameter of the URI, parameterArray[1] is the second.
35
+ #The parameters are used to specify what data you want in your uri.
36
+ #E.G. /order-service/order/100051 would take a parameter array of Array["100051"]
37
+ #This works with URIs with two parameters as well and should be in the form of Array["100051",20] or similar
38
+ public
39
+ def call(resourceURI, requestType,parameterArray = nil,postBody = nil)
40
+ #Checks if the string includes http or https, if it does this means a full URI was passed in
41
+ if (resourceURI.downcase["https"] || resourceURI.downcase["http"])
42
+ requestToAdd = Request.new(@requestIncrementID,resourceURI,requestType,@currentConnection.accountID,postBody)
43
+ @requestIncrementID += 1
44
+ else
45
+ requestToAdd = Request.new(@requestIncrementID,buildRequestURL(resourceURI,requestType,parameterArray),requestType,@currentConnection.accountID,postBody)
46
+ end
47
+ addRequestToQueue(requestToAdd) if requestToAdd != nil
48
+ return @requestIncrementID - 1
49
+ end
50
+
51
+ #Update method, this method allows you to specify a 'delayTime' in which the function is delayed each run.
52
+ #Default is '1', which means it will sleep 1 second after each run (running once every second where possible)
53
+ #Empties the requestQueue and sends them as HTTP requests based on the type of method (Post, get, etc)
54
+ #Pushes responses to responseQueue
55
+ #TODO: Change this from 'delayTime' to implement rate limiting
56
+ public
57
+ def update(delayTime = 1)
58
+ current = Thread.new do
59
+ while @requestQueue.length > 0 do
60
+ requestString = @requestQueue.pop
61
+ uri = URI(requestString.uri.to_s)
62
+ Net::HTTP.start(uri.host,uri.port) do |http|
63
+ puts requestString.requestType.to_s
64
+ case requestString.requestType
65
+ when 'post'
66
+ request = Net::HTTP::Post.new uri
67
+ request.body = requestString.requestBody
68
+ request.add_field('brightpearl-app-ref',@currentConnection.appRef)
69
+ request.add_field('brightpearl-account-token',@currentConnection.appToken)
70
+ if @apiVersion.to_s.casecmp('use') || @apiVersion.to_s.casecmp('eu1')
71
+ response = http.request request
72
+ @responseQueue.push(Response.new(requestString,response))
73
+ else
74
+ puts 'Error - Invalid datacenter supplied, please enter a valid datacenter.'
75
+ end
76
+ when 'get'
77
+ request = Net::HTTP::Get.new uri
78
+ request.add_field('brightpearl-app-ref',@currentConnection.appRef)
79
+ request.add_field('brightpearl-account-token',@currentConnection.appToken)
80
+ if @apiVersion.to_s.casecmp('use') || @apiVersion.to_s.casecmp('eu1')
81
+ response = http.request request
82
+ @responseQueue.push(Response.new(requestString,response))
83
+ else
84
+ puts 'Error - Invalid datacenter supplied, please enter a valid datacenter.'
85
+ end
86
+ when 'patch'
87
+ request = Net::HTTP::Patch.new uri
88
+ request.body = requestString.requestBody
89
+ request.add_field('brightpearl-app-ref',@currentConnection.appRef)
90
+ request.add_field('brightpearl-account-token',@currentConnection.appToken)
91
+ if @apiVersion.to_s.casecmp('use') || @apiVersion.to_s.casecmp('eu1')
92
+ response = http.request request
93
+ @responseQueue.push(Response.new(requestString,response))
94
+ else
95
+ puts 'Error - Invalid datacenter supplied, please enter a valid datacenter.'
96
+ end
97
+ when 'put'
98
+ request = Net::HTTP::Put.new uri
99
+ request.body = requestString.requestBody
100
+ request.add_field('brightpearl-app-ref',@currentConnection.appRef)
101
+ request.add_field('brightpearl-account-token',@currentConnection.appToken)
102
+ if @apiVersion.to_s.casecmp('use') || @apiVersion.to_s.casecmp('eu1')
103
+ response = http.request request
104
+ @responseQueue.push(Response.new(requestString,response))
105
+ else
106
+ puts 'Error - Invalid datacenter supplied, please enter a valid datacenter.'
107
+ end
108
+ when 'delete'
109
+ request = Net::HTTP::Delete.new uri
110
+ request.body = requestString.requestBody
111
+ request.add_field('brightpearl-app-ref',@currentConnection.appRef)
112
+ request.add_field('brightpearl-account-token',@currentConnection.appToken)
113
+ if @apiVersion.to_s.casecmp('use') || @apiVersion.to_s.casecmp('eu1')
114
+ response = http.request request
115
+ @responseQueue.push(Response.new(requestString,response))
116
+ else
117
+ puts 'Error - Invalid datacenter supplied, please enter a valid datacenter.'
118
+ end
119
+ when 'search'
120
+ request = Net::HTTP::Get.new uri
121
+ request.add_field('brightpearl-app-ref',@currentConnection.appRef)
122
+ request.add_field('brightpearl-account-token',@currentConnection.appToken)
123
+ if @apiVersion.to_s.casecmp('use') || @apiVersion.to_s.casecmp('eu1')
124
+ response = http.request request
125
+ @responseQueue.push(Response.new(requestString,response))
126
+ else
127
+ puts 'Error - Invalid datacenter supplied, please enter a valid datacenter.'
128
+ end
129
+ else
130
+ puts 'Invalid request Type, please input a valid request Type for your request...'
131
+ end
132
+ end
133
+ sleep(delayTime)
134
+ end
135
+ end
136
+ current.join
137
+ end
138
+
139
+ #This method is meant to build a URI out of an input resource URI, the parameterName
140
+ #and the value passed from the user/developer
141
+ public
142
+ def buildRequestURL(resourceURI,requestType,arrayOfParameters)
143
+ arrayOfParameters ||= Array[nil]
144
+ if (arrayOfParameters!= nil && arrayOfParameters.is_a?(Array) == false)
145
+ puts "Array of values not entered to build request URL, please enter an array of values"
146
+ end
147
+ url = 'http://ws-' << @currentConnection.dataCenter<< '.brightpearl.com/' << @currentConnection.apiVersion << '/' << @currentConnection.accountID << resourceURI
148
+ if(requestType.to_s.casecmp('GET') || requestType.to_s.casecmp('OPTIONS') || requestType.to_s.caseCMP('POST')|| requestType.to_s.casecmp('PATCH') || requestType.to_s.casecmp('PUT') || requestType.to_s.casecmp('DELETE'))
149
+ uriparameters = url.scan(/{.+?}/)#scans the request string for all paramaters in the URI/URL
150
+ uriparameters.each_with_index do |x,index| #for each paramater found we replace the value
151
+ if index == 0
152
+ url.gsub!(x,arrayOfParameters[0].to_s)
153
+ elsif index == 1
154
+ url.gsub!(x,arrayOfParameters[1].to_s)
155
+ else
156
+ puts "Invalid amount of paramaters specified in URL. Contact Developer/administrator as this application may need updated!"
157
+ end
158
+ end
159
+ end
160
+ return url
161
+ end
162
+
163
+ #This method adds requests to the request queue
164
+ private
165
+ def addRequestToQueue(data)
166
+ @requestQueue.push(data)
167
+ end
168
+
169
+ end
@@ -0,0 +1,189 @@
1
+ require_relative '../applib/request_method'
2
+ require 'open-uri'
3
+ require 'json'
4
+ class RequestMethodHandler
5
+
6
+ public
7
+ def initialize
8
+ @requestMethods = generateRequestMethods()
9
+ end
10
+
11
+ #Gets the supplied request method object by a passed in resource,
12
+ #and methodType(Get,post,put, etc)if not null, if no methodType is passed in it will return the first result
13
+ public
14
+ def getRequestMethodByResource(resource,methodType = nil)
15
+ if methodType == nil
16
+ if @requestMethods[resource] != nil
17
+ return @requestMethods[resource]
18
+ end
19
+ else
20
+ @requestMethods.detect {|k,v| return v if v.resource == resource && v.HTTPMethod.to_s.casecmp(methodType.to_s) == 0}
21
+ end
22
+ end
23
+
24
+ #Returns the request methods URI from an input resource
25
+ #Optional parameter of service type to allow you to specify which resource service type you want (Get,Post,put,etc)
26
+ public
27
+ def getRequestMethodURI(resource,methodType = nil)
28
+ if methodType == nil
29
+ if @requestMethods[resource] != nil
30
+ puts "Resourced found by name of #{resource}"
31
+ return @requestMethods[resource].uri
32
+ else
33
+ puts "No Resource Found by the name of #{resource}"
34
+ end
35
+ else
36
+ @requestMethods.detect {|k,v| return v.uri if v.resource == resource && v.HTTPMethod.to_s.casecmp(methodType.to_s) == 0}
37
+ end
38
+ end
39
+
40
+
41
+ #This method Gets the given request parameters by resource and returns a hash with all the parameters.
42
+ #Has optional methodType paramater to only return resource of a certain method type (Post,put, etc)
43
+ #Returned keys in hash are: name,service, method,uri,response,apiDomain,urls,authorizeServer,authorizeInstance,requests
44
+ public
45
+ def getRequestParemetersByResource(resource,methodType = nil)
46
+ if methodType == nil
47
+ @requestMethods.each do |index,val|
48
+ if resource.to_s.casecmp(index) == 0
49
+ parameterHash =
50
+ {
51
+ "name" => val.instance_variable_get(:@name),
52
+ "service" => val.instance_variable_get(:@service),
53
+ "HTTPMethod" => val.instance_variable_get(:@HTTPMethod),
54
+ "uri" => val.instance_variable_get(:@uri),
55
+ "response" => val.instance_variable_get(:@response),
56
+ "apiDomain" => val.instance_variable_get(:@apiDomain),
57
+ "urls" => val.instance_variable_get(:@urls),
58
+ "authorizeServer" => val.instance_variable_get(:@authorizeServer),
59
+ "authorizeInstance" => val.instance_variable_get(:@authorizeInstance),
60
+ "requests" => val.instance_variable_get(:@requests)
61
+ }
62
+ return parameterHash if parameterHash != nil
63
+ else
64
+ #Resource doesn't match, continue to loop
65
+ end
66
+ end
67
+
68
+ puts "No matching Resource, please input a valid resource. To list resources use listRequestMethodsByResource()"
69
+ else
70
+ @requestMethods.detect do |key,val|
71
+ if val.resource == resource && val.HTTPMethod.to_s.casecmp(methodType.to_s) == 0
72
+ parameterHash =
73
+ {
74
+ "name" => val.instance_variable_get(:@name),
75
+ "service" => val.instance_variable_get(:@service),
76
+ "@HTTPMethod" => val.instance_variable_get(:@HTTPMethod),
77
+ "uri" => val.instance_variable_get(:@uri),
78
+ "response" => val.instance_variable_get(:@response),
79
+ "apiDomain" => val.instance_variable_get(:@apiDomain),
80
+ "urls" => val.instance_variable_get(:@urls),
81
+ "authorizeServer" => val.instance_variable_get(:@authorizeServer),
82
+ "authorizeInstance" => val.instance_variable_get(:@authorizeInstance),
83
+ "requests" => val.instance_variable_get(:@requests)
84
+ }
85
+ return parameterHash if parameterHash != nil
86
+ else
87
+ #Resource doesn't match, continue to loop
88
+ end
89
+ end
90
+ puts 'No matching Resource, please input a valid resource. To list resources use listRequestMethodsByResource()'
91
+ end
92
+ end
93
+
94
+ #Lists current request methods
95
+ #(Generated from generateRequestMethods, which pulls from http://api-docs.brightpearl.com/json-index.html)
96
+ #Defaults to show 'all' possible request methods
97
+ #allows a resource to be passed to show only a given request method's parameters
98
+ #EX listRequestMethodsByResource('zone')
99
+ #Option parameter of method type to only list resources of a given method type (Post,put,etc)
100
+ public
101
+ def listRequestMethodsByResource(resource = 'all',methodType = nil)
102
+ if methodType == nil
103
+ @requestMethods.each do |index,val|
104
+ if resource.to_s.casecmp('all') == 0
105
+ puts "---------------------------------------------------------------------------------------"
106
+ puts "Resource: #{val.instance_variable_get(:@resource)}"
107
+ puts "Name: #{val.instance_variable_get(:@name)}"
108
+ puts "Service: #{val.instance_variable_get(:@service)}"
109
+ puts "Method: #{val.instance_variable_get(:@HTTPMethod)}"
110
+ puts "URI: #{val.instance_variable_get(:@uri)}"
111
+ puts "Response: #{val.instance_variable_get(:@response)}"
112
+ puts "API Domain: #{val.instance_variable_get(:@apiDomain)}"
113
+ puts "URLs: #{val.instance_variable_get(:@urls)}"
114
+ puts "Authorize Server: #{val.instance_variable_get(:@authorizeServer)}"
115
+ puts "Authorize Instance: #{val.instance_variable_get(:@authorizeInstance)}"
116
+ puts "Requests: #{val.instance_variable_get(:@requests)}"
117
+ puts "---------------------------------------------------------------------------------------\n\n"
118
+ else
119
+ if resource.to_s.casecmp(val.instance_variable_get(:@resource)) == 0
120
+ puts "---------------------------------------------------------------------------------------"
121
+ puts "Resource: #{val.instance_variable_get(:@resource)}"
122
+ puts "Name: #{val.instance_variable_get(:@name)}"
123
+ puts "Service: #{val.instance_variable_get(:@service)}"
124
+ puts "Method: #{val.instance_variable_get(:@HTTPMethod)}"
125
+ puts "URI: #{val.instance_variable_get(:@uri)}"
126
+ puts "Response: #{val.instance_variable_get(:@response)}"
127
+ puts "API Domain: #{val.instance_variable_get(:@apiDomain)}"
128
+ puts "URLs: #{val.instance_variable_get(:@urls)}"
129
+ puts "Authorize Server: #{val.instance_variable_get(:@authorizeServer)}"
130
+ puts "Authorize Instance: #{val.instance_variable_get(:@authorizeInstance)}"
131
+ puts "Requests: #{val.instance_variable_get(:@requests)}"
132
+ puts "---------------------------------------------------------------------------------------\n\n"
133
+ end
134
+ end
135
+ end
136
+ else
137
+ @requestMethods.each do |index,val|
138
+ if resource.to_s.casecmp('all') == 0 && val.HTTPMethod.to_s.casecmp(methodType.to_s) == 0
139
+ puts "---------------------------------------------------------------------------------------"
140
+ puts "Resource: #{val.instance_variable_get(:@resource)}"
141
+ puts "Name: #{val.instance_variable_get(:@name)}"
142
+ puts "Service: #{val.instance_variable_get(:@service)}"
143
+ puts "Method: #{val.instance_variable_get(:@HTTPMethod)}"
144
+ puts "URI: #{val.instance_variable_get(:@uri)}"
145
+ puts "Response: #{val.instance_variable_get(:@response)}"
146
+ puts "API Domain: #{val.instance_variable_get(:@apiDomain)}"
147
+ puts "URLs: #{val.instance_variable_get(:@urls)}"
148
+ puts "Authorize Server: #{val.instance_variable_get(:@authorizeServer)}"
149
+ puts "Authorize Instance: #{val.instance_variable_get(:@authorizeInstance)}"
150
+ puts "Requests: #{val.instance_variable_get(:@requests)}"
151
+ puts "---------------------------------------------------------------------------------------\n\n"
152
+ else
153
+ if resource.to_s.casecmp(val.instance_variable_get(:@resource)) == 0 && val.HTTPMethod.to_s.casecmp(methodType.to_s) == 0
154
+ puts "---------------------------------------------------------------------------------------"
155
+ puts "Resource: #{val.instance_variable_get(:@resource)}"
156
+ puts "Name: #{val.instance_variable_get(:@name)}"
157
+ puts "Service: #{val.instance_variable_get(:@service)}"
158
+ puts "Method: #{val.instance_variable_get(:@HTTPMethod)}"
159
+ puts "URI: #{val.instance_variable_get(:@uri)}"
160
+ puts "Response: #{val.instance_variable_get(:@response)}"
161
+ puts "API Domain: #{val.instance_variable_get(:@apiDomain)}"
162
+ puts "URLs: #{val.instance_variable_get(:@urls)}"
163
+ puts "Authorize Server: #{val.instance_variable_get(:@authorizeServer)}"
164
+ puts "Authorize Instance: #{val.instance_variable_get(:@authorizeInstance)}"
165
+ puts "Requests: #{val.instance_variable_get(:@requests)}"
166
+ puts "---------------------------------------------------------------------------------------\n\n"
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
172
+
173
+
174
+ #This Generates all possible request methods to the Brightpearl API and loads them into the @requestMethods hash.
175
+ #The Request methods have their own class so each part of the data (Name, resource, URI, etc) can be read.
176
+ #Needed to run in the INIT method for other functions in request_method_handler.rb to work
177
+ private
178
+ def generateRequestMethods
179
+ #TODO - rewrite this not using open-uri
180
+ json = open('http://api-docs.brightpearl.com/json-index.html').read
181
+ #puts json
182
+ temp_hash = Hash.new()
183
+ data_hash = JSON.parse(json) #Each value in the hash #(name,service,resource,method,uri,responses,apiDomain,urls,authorizeServer,authorizeInstance,requests)
184
+ data_hash.each_with_index { |val,index| temp_hash.store(val, RequestMethod.new(data_hash[index]['name'],data_hash[index]['service'],data_hash[index]['resource'],data_hash[index]['method'],data_hash[index]['uri'],data_hash[index]['responses'],data_hash[index]['apiDomain'],data_hash[index]['urls'],data_hash[index]['authorizeServer'],data_hash[index]['authorizeInstance'],data_hash[index]['requests']))} #RequestMethod.new(data_hash[x]['name'].to_s,data_hash[x]['service'].to_s,data_hash[x]['resource'].to_s,data_hash[x]['method'].to_s,data_hash[x]['uri'].to_s,data_hash[x]['responses'].to_s,data_hash[x]['apiDomain'].to_s,data_hash[x]['urls'].to_s,data_hash[x]['authorizeServer'].to_s,data_hash[x]['authorizeInstance'].to_s,data_hash[x]['requests'].to_s)
185
+ temp_hash
186
+ end
187
+
188
+
189
+ end
@@ -0,0 +1,62 @@
1
+ require_relative "../appLib/response.rb"
2
+ class ResponseHandler
3
+
4
+ attr_reader :responseHash
5
+
6
+ public
7
+ def initialize(responseQueue)
8
+ @responseHash = queueToHash(responseQueue)
9
+ end
10
+
11
+ #Merges the inputed queue into the responseHash using the queueToHash method and the Hash's .merge method
12
+ public
13
+ def updateHash(queue)
14
+ @responseHash = queueToHash(queue).merge(@responseHash)
15
+ end
16
+
17
+ #Clears out the response queue but is self explanatory :)
18
+ public
19
+ def clearResponseHash
20
+ @responseHash.clear
21
+ end
22
+
23
+ #Returns a hash of Responses based on the input URI
24
+ public
25
+ def getResponsesByURI(uri)
26
+ returnHash = Hash.new
27
+ @responseHash.each do |index,value|
28
+ if value.getRequestURI.to_s.casecmp(uri)
29
+ returnHash[index] = value
30
+ end
31
+ end
32
+ returnHash
33
+ end
34
+
35
+ private
36
+ def clearResponsesByURI(uri)
37
+ #TODO: Not implemented
38
+ end
39
+
40
+ public
41
+ def listResponses
42
+ @responseHash.each do |key,value|
43
+ puts "Request ID: #{key} had a response code of #{value.code}, response body of #{value.body}, response message of #{value.msg}"
44
+ puts "For URI: #{value.getRequestURI}, and Post Body: #{value.getPostBody}"
45
+ end
46
+ end
47
+
48
+ #Adds responses into a hash. The Key is the Request ID of the request that was made that gave the response (Should be unique), the value is the response object.
49
+ private
50
+ def queueToHash(queue)
51
+ returnHash = Hash.new
52
+ current = Thread.new do
53
+ while queue.length > 0
54
+ response = queue.pop
55
+ returnHash[response.getRequestID] = response
56
+ end
57
+ end
58
+ current.join
59
+ returnHash
60
+ end
61
+
62
+ end
File without changes
File without changes
File without changes
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: BPRubySDK
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Rob
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: This gem is a wrapper to the Brightpearl API. To see usage and documentation
56
+ details please visit https://github.com/xaviarrob/BPRubySDK/
57
+ email:
58
+ - robert.nicholas@brightpearl.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - lib/BPRubySDK.rb
64
+ - lib/BPRubySDK/version.rb
65
+ - lib/applib/connection.rb
66
+ - lib/applib/request.rb
67
+ - lib/applib/request_method.rb
68
+ - lib/applib/response.rb
69
+ - lib/handlers/request_handler.rb
70
+ - lib/handlers/request_method_handler.rb
71
+ - lib/handlers/response_handler.rb
72
+ - lib/util/csv_to_json.rb
73
+ - lib/util/file_log.rb
74
+ - lib/util/json_to_csv.rb
75
+ homepage: http://www.brightpearl.com
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.6.8
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: A Ruby wrapper to the Brightpearl API
99
+ test_files: []