flowcommerce 0.1.22 → 0.1.23
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 +4 -4
- data/lib/flow_commerce/client.rb +3 -2
- data/lib/flow_commerce/flow_api_v0_client.rb +87 -43
- data/lib/flowcommerce.rb +1 -0
- data/lib/logging_http_client.rb +39 -0
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0754634abaa88c538758514d93837c807d6668c9
|
4
|
+
data.tar.gz: 498950a55b09d06d15580dac8d02ca0a97ca1a28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 509f5bad7cc26ce4be51514c05148c3034a8e20963f523fda9dc338ba06addf1276798caefa05f0b496578672b6edc2c67dacedcfbd83e83501b7c11c8dad258
|
7
|
+
data.tar.gz: 2f5597d0c73b79e0d3240770942e6a458c03881fd679410854932a403a87e963bd9f0855c15d53f55377f551f5e3b81ac99ce86abedcb57bf15b99d831edaae4
|
data/lib/flow_commerce/client.rb
CHANGED
@@ -13,6 +13,7 @@ module FlowCommerce
|
|
13
13
|
def FlowCommerce.instance(opts={})
|
14
14
|
base_url = opts[:base_url].to_s.strip
|
15
15
|
token = opts[:token].to_s.strip
|
16
|
+
http_handler = opts[:http_handler]
|
16
17
|
|
17
18
|
if token.empty?
|
18
19
|
token = ENV['FLOW_TOKEN'].to_s.strip
|
@@ -38,9 +39,9 @@ module FlowCommerce
|
|
38
39
|
auth = Io::Flow::V0::HttpClient::Authorization.basic(token)
|
39
40
|
|
40
41
|
if base_url.empty?
|
41
|
-
Io::Flow::V0::Client.at_base_url(:authorization => auth)
|
42
|
+
Io::Flow::V0::Client.at_base_url(:authorization => auth, :http_handler => http_handler)
|
42
43
|
else
|
43
|
-
Io::Flow::V0::Client.new(base_url, :authorization => auth)
|
44
|
+
Io::Flow::V0::Client.new(base_url, :authorization => auth, :http_handler => http_handler)
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Generated by apidoc - http://www.apidoc.me
|
2
2
|
# Service version: 0.2.79
|
3
|
-
# apidoc:0.11.
|
3
|
+
# apidoc:0.11.75 http://www.apidoc.me/flow/api/0.2.80/ruby_client
|
4
4
|
|
5
5
|
require 'cgi'
|
6
6
|
require 'net/http'
|
@@ -25,7 +25,7 @@ module Io
|
|
25
25
|
|
26
26
|
BASE_URL = 'https://api.flow.io' unless defined?(Constants::BASE_URL)
|
27
27
|
NAMESPACE = 'io.flow.v0' unless defined?(Constants::NAMESPACE)
|
28
|
-
USER_AGENT = 'apidoc:0.11.
|
28
|
+
USER_AGENT = 'apidoc:0.11.75 http://www.apidoc.me/flow/api/0.2.80/ruby_client' unless defined?(Constants::USER_AGENT)
|
29
29
|
VERSION = '0.2.79' unless defined?(Constants::VERSION)
|
30
30
|
VERSION_MAJOR = 0 unless defined?(VERSION_MAJOR)
|
31
31
|
|
@@ -35,8 +35,11 @@ module Io
|
|
35
35
|
|
36
36
|
def initialize(url, opts={})
|
37
37
|
@url = HttpClient::Preconditions.assert_class('url', url, String)
|
38
|
+
@base_url = URI(url)
|
38
39
|
@authorization = HttpClient::Preconditions.assert_class_or_nil('authorization', opts.delete(:authorization), HttpClient::Authorization)
|
39
40
|
@default_headers = HttpClient::Preconditions.assert_class('default_headers', opts.delete(:default_headers) || {}, Hash)
|
41
|
+
@http_handler = opts.delete(:http_handler) || HttpClient::DefaultHttpHandler.new
|
42
|
+
|
40
43
|
HttpClient::Preconditions.assert_empty_opts(opts)
|
41
44
|
HttpClient::Preconditions.check_state(url.match(/http.+/i), "URL[%s] must start with http" % url)
|
42
45
|
end
|
@@ -48,7 +51,7 @@ module Io
|
|
48
51
|
|
49
52
|
def request(path=nil)
|
50
53
|
HttpClient::Preconditions.assert_class_or_nil('path', path, String)
|
51
|
-
request = HttpClient::Request.new(
|
54
|
+
request = HttpClient::Request.new(@http_handler, @base_url, path.to_s).with_header('User-Agent', Constants::USER_AGENT).with_header('X-Apidoc-Version', Constants::VERSION).with_header('X-Apidoc-Version-Major', Constants::VERSION_MAJOR)
|
52
55
|
|
53
56
|
@default_headers.each do |key, value|
|
54
57
|
request = request.with_header(key, value)
|
@@ -22949,10 +22952,86 @@ module Io
|
|
22949
22952
|
# ===== END OF SERVICE DEFINITION =====
|
22950
22953
|
module HttpClient
|
22951
22954
|
|
22955
|
+
class HttpHandler
|
22956
|
+
|
22957
|
+
# Returns a client instance to use
|
22958
|
+
#
|
22959
|
+
# @param base_uri The base URI for this API
|
22960
|
+
# @param path the Requested full http path (including any query strings)
|
22961
|
+
def instance(base_uri, path)
|
22962
|
+
raise "Override in subclass"
|
22963
|
+
end
|
22964
|
+
|
22965
|
+
end
|
22966
|
+
|
22967
|
+
class HttpHandlerInstance
|
22968
|
+
|
22969
|
+
# Executes a request. The provided request object will be an
|
22970
|
+
# instance of Net::HTTP (e.g. Net::HTTP::Get)
|
22971
|
+
def execute(request)
|
22972
|
+
raise "Override in subclass"
|
22973
|
+
end
|
22974
|
+
|
22975
|
+
end
|
22976
|
+
|
22977
|
+
class DefaultHttpHandler < HttpHandler
|
22978
|
+
|
22979
|
+
def instance(base_uri, path)
|
22980
|
+
DefaultHttpHandlerInstance.new(base_uri)
|
22981
|
+
end
|
22982
|
+
|
22983
|
+
end
|
22984
|
+
|
22985
|
+
class DefaultHttpHandlerInstance < HttpHandlerInstance
|
22986
|
+
|
22987
|
+
attr_reader :client
|
22988
|
+
|
22989
|
+
def initialize(base_uri)
|
22990
|
+
@base_uri = Preconditions.assert_class('base_uri', base_uri, URI)
|
22991
|
+
@client = Net::HTTP.new(@base_uri.host, @base_uri.port)
|
22992
|
+
if @base_uri.scheme == "https"
|
22993
|
+
configure_ssl
|
22994
|
+
end
|
22995
|
+
end
|
22996
|
+
|
22997
|
+
def execute(request)
|
22998
|
+
response = begin
|
22999
|
+
@client.request(request)
|
23000
|
+
rescue SocketError => e
|
23001
|
+
raise Exception.new("Error accessing uri[#{full_uri(request.path)}]: #{e}")
|
23002
|
+
end
|
23003
|
+
|
23004
|
+
case response
|
23005
|
+
when Net::HTTPSuccess
|
23006
|
+
response.body
|
23007
|
+
else
|
23008
|
+
body = response.body rescue nil
|
23009
|
+
raise HttpClient::ServerError.new(response.code.to_i, response.message, :body => body, :uri => full_uri(request.path).to_s)
|
23010
|
+
end
|
23011
|
+
end
|
23012
|
+
|
23013
|
+
def full_uri(path)
|
23014
|
+
File.join(@base_uri.to_s, path)
|
23015
|
+
end
|
23016
|
+
|
23017
|
+
# Called to configure SSL if the base uri requires it
|
23018
|
+
def configure_ssl
|
23019
|
+
@client.use_ssl = true
|
23020
|
+
@client.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
23021
|
+
@client.cert_store = OpenSSL::X509::Store.new
|
23022
|
+
@client.cert_store.set_default_paths
|
23023
|
+
end
|
23024
|
+
|
23025
|
+
end
|
23026
|
+
|
22952
23027
|
class Request
|
22953
23028
|
|
22954
|
-
|
22955
|
-
|
23029
|
+
attr_reader :path
|
23030
|
+
|
23031
|
+
def initialize(http_handler, base_uri, path)
|
23032
|
+
@http_handler = http_handler
|
23033
|
+
@base_uri = Preconditions.assert_class('base_uri', base_uri, URI)
|
23034
|
+
@path = Preconditions.assert_class('path', path, String)
|
22956
23035
|
@params = nil
|
22957
23036
|
@body = nil
|
22958
23037
|
@auth = nil
|
@@ -23002,26 +23081,6 @@ module Io
|
|
23002
23081
|
self
|
23003
23082
|
end
|
23004
23083
|
|
23005
|
-
# Creates a new Net:HTTP client. The client returned should be
|
23006
|
-
# fully configured to make a request.
|
23007
|
-
def new_http_client
|
23008
|
-
client = Net::HTTP.new(@uri.host, @uri.port)
|
23009
|
-
if @uri.scheme == "https"
|
23010
|
-
configure_ssl(client)
|
23011
|
-
end
|
23012
|
-
client
|
23013
|
-
end
|
23014
|
-
|
23015
|
-
# If HTTPS is required, this method accepts an HTTP Client and configures SSL
|
23016
|
-
def configure_ssl(http)
|
23017
|
-
Preconditions.assert_class('http', http, Net::HTTP)
|
23018
|
-
http.use_ssl = true
|
23019
|
-
http.ssl_version = :TLSv1_2
|
23020
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
23021
|
-
http.cert_store = OpenSSL::X509::Store.new
|
23022
|
-
http.cert_store.set_default_paths
|
23023
|
-
end
|
23024
|
-
|
23025
23084
|
def get(&block)
|
23026
23085
|
do_request(Net::HTTP::Get, &block)
|
23027
23086
|
end
|
@@ -23053,7 +23112,7 @@ module Io
|
|
23053
23112
|
def do_request(klass)
|
23054
23113
|
Preconditions.assert_class('klass', klass, Class)
|
23055
23114
|
|
23056
|
-
uri =
|
23115
|
+
uri = path.dup
|
23057
23116
|
if q = to_query(@params)
|
23058
23117
|
uri += "?%s" % q
|
23059
23118
|
end
|
@@ -23086,10 +23145,10 @@ module Io
|
|
23086
23145
|
request.add_field(key, value)
|
23087
23146
|
}
|
23088
23147
|
|
23089
|
-
curl << "'%s'" %
|
23148
|
+
curl << "'%s%s'" % [@base_uri, path]
|
23090
23149
|
# DEBUG puts curl.join(" ")
|
23091
23150
|
|
23092
|
-
raw_response =
|
23151
|
+
raw_response = @http_handler.instance(@base_uri, request.path).execute(request)
|
23093
23152
|
response = raw_response.to_s == "" ? nil : JSON.parse(raw_response)
|
23094
23153
|
|
23095
23154
|
if block_given?
|
@@ -23111,21 +23170,6 @@ module Io
|
|
23111
23170
|
parts.empty? ? nil : parts.join("&")
|
23112
23171
|
end
|
23113
23172
|
|
23114
|
-
def http_request(request)
|
23115
|
-
response = begin
|
23116
|
-
new_http_client.request(request)
|
23117
|
-
rescue SocketError => e
|
23118
|
-
raise Exception.new("Error accessing uri[#{@uri}]: #{e}")
|
23119
|
-
end
|
23120
|
-
|
23121
|
-
case response
|
23122
|
-
when Net::HTTPSuccess
|
23123
|
-
response.body
|
23124
|
-
else
|
23125
|
-
body = response.body rescue nil
|
23126
|
-
raise HttpClient::ServerError.new(response.code.to_i, response.message, :body => body, :uri => @uri.to_s)
|
23127
|
-
end
|
23128
|
-
end
|
23129
23173
|
end
|
23130
23174
|
|
23131
23175
|
class ServerError < StandardError
|
data/lib/flowcommerce.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
class LoggingHttpClient < ::Io::Flow::V0::HttpClient::DefaultHttpHandler
|
5
|
+
|
6
|
+
def initialize(base_uri, path)
|
7
|
+
super(base_uri)
|
8
|
+
@logger = Logger.new(path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute(request)
|
12
|
+
original_open = client.open_timeout
|
13
|
+
original_read = client.read_timeout
|
14
|
+
|
15
|
+
start_time = Time.now.utc.round(10)
|
16
|
+
@logger.info "start %s %s" % [request.method, request.path]
|
17
|
+
|
18
|
+
if request.path.start_with?("/organizations")
|
19
|
+
# Contrived example to show how client settings can be adjusted
|
20
|
+
client.open_timeout = 60
|
21
|
+
client.read_timeout = 60
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
super
|
26
|
+
ensure
|
27
|
+
client.open_timeout = original_open
|
28
|
+
client.read_timeout = original_read
|
29
|
+
|
30
|
+
end_time = Time.now.utc.round(10)
|
31
|
+
duration = ((end_time - start_time)*1000).round(0)
|
32
|
+
@logger.info "complete %s %s %s ms" % [request.method, request.path, duration]
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flowcommerce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flow Commerce, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bigdecimal
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Native ruby client for the Flow REST API. Detailed information at http://apidoc.me/flow
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- lib/flow_commerce/client.rb
|
49
49
|
- lib/flow_commerce/flow_api_v0_client.rb
|
50
50
|
- lib/flowcommerce.rb
|
51
|
+
- lib/logging_http_client.rb
|
51
52
|
homepage: https://github.com/flowcommerce/ruby-sdk
|
52
53
|
licenses:
|
53
54
|
- MIT
|
@@ -58,17 +59,17 @@ require_paths:
|
|
58
59
|
- lib
|
59
60
|
required_ruby_version: !ruby/object:Gem::Requirement
|
60
61
|
requirements:
|
61
|
-
- -
|
62
|
+
- - '>='
|
62
63
|
- !ruby/object:Gem::Version
|
63
64
|
version: '0'
|
64
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
|
-
- -
|
67
|
+
- - '>='
|
67
68
|
- !ruby/object:Gem::Version
|
68
69
|
version: '0'
|
69
70
|
requirements: []
|
70
71
|
rubyforge_project:
|
71
|
-
rubygems_version: 2.
|
72
|
+
rubygems_version: 2.0.14.1
|
72
73
|
signing_key:
|
73
74
|
specification_version: 4
|
74
75
|
summary: Native ruby client for the Flow REST API.
|