cielo24 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cielo24.rb +9 -9
- data/lib/cielo24/actions.rb +287 -274
- data/lib/cielo24/enums.rb +153 -153
- data/lib/cielo24/options.rb +219 -219
- data/lib/cielo24/version.rb +3 -3
- data/lib/cielo24/web_utils.rb +101 -74
- metadata +17 -3
data/lib/cielo24/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Cielo24
|
2
|
-
VERSION = '0.0.
|
3
|
-
end
|
1
|
+
module Cielo24
|
2
|
+
VERSION = '0.0.17'
|
3
|
+
end
|
data/lib/cielo24/web_utils.rb
CHANGED
@@ -1,75 +1,102 @@
|
|
1
|
-
module Cielo24
|
2
|
-
class WebUtils
|
3
|
-
|
4
|
-
require 'json'
|
5
|
-
require 'httpclient'
|
6
|
-
require 'timeout'
|
7
|
-
require 'logger'
|
8
|
-
require 'tzinfo'
|
9
|
-
include JSON
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
http_client
|
25
|
-
http_client.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
1
|
+
module Cielo24
|
2
|
+
class WebUtils
|
3
|
+
|
4
|
+
require 'json'
|
5
|
+
require 'httpclient'
|
6
|
+
require 'timeout'
|
7
|
+
require 'logger'
|
8
|
+
require 'tzinfo'
|
9
|
+
include JSON
|
10
|
+
include TZInfo
|
11
|
+
|
12
|
+
BASIC_TIMEOUT = 60 # seconds (1 minute)
|
13
|
+
DOWNLOAD_TIMEOUT = 300 # seconds (5 minutes)
|
14
|
+
UPLOAD_TIMEOUT = 60*60*24*7 # seconds (1 week)
|
15
|
+
SERVER_TZ = 'America/Los_Angeles'
|
16
|
+
LOGGER = Logger.new(STDOUT)
|
17
|
+
|
18
|
+
def self.get_json(uri, method, timeout, query=nil, headers=nil, body=nil)
|
19
|
+
response = http_request(uri, method, timeout, query, headers, body)
|
20
|
+
return json_parse(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.http_request(uri, method, timeout, query=nil, headers=nil, body=nil)
|
24
|
+
http_client = HTTPClient.new
|
25
|
+
http_client.cookie_manager = nil
|
26
|
+
http_client.send_timeout = UPLOAD_TIMEOUT
|
27
|
+
LOGGER.info(uri + (query.nil? ? '' : '?' + URI.encode_www_form(query)))
|
28
|
+
|
29
|
+
# Timeout block:
|
30
|
+
begin
|
31
|
+
# Error is raised if the following block fails to execute in 'timeout' sec:
|
32
|
+
Timeout.timeout(timeout) { # nil timeout = infinite
|
33
|
+
|
34
|
+
response = http_client.request(method, uri, query, body, headers, nil)
|
35
|
+
# Handle web errors
|
36
|
+
if response.status_code == 200 or response.status_code == 204
|
37
|
+
return response.body
|
38
|
+
else
|
39
|
+
json = json_parse(response.body)
|
40
|
+
raise WebError.new(response.status_code, json['ErrorType'], json['ErrorComment'])
|
41
|
+
end
|
42
|
+
|
43
|
+
}
|
44
|
+
rescue Timeout::Error
|
45
|
+
raise TimeoutError.new('The HTTP session has timed out.')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.to_utc(s)
|
50
|
+
return s if s.empty?
|
51
|
+
tz = Timezone.get(SERVER_TZ)
|
52
|
+
local = DateTime.iso8601(s)
|
53
|
+
utc = tz.local_to_utc local
|
54
|
+
format = '%Y-%m-%dT%H:%M:%S.%L%z' # iso8601 with milliseconds
|
55
|
+
utc.strftime(format)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.json_parse(s)
|
59
|
+
begin
|
60
|
+
return JSON.parse(s)
|
61
|
+
rescue JSON::ParserError
|
62
|
+
raise ParsingError.new("Bad JSON String: \"#{s}\"")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class CieloError < StandardError
|
68
|
+
attr_reader :type
|
69
|
+
def initialize(type, comment)
|
70
|
+
super(comment)
|
71
|
+
@type = type
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_s
|
75
|
+
"#{@type} - #{super.to_s}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class WebError < CieloError
|
80
|
+
attr_reader :status_code
|
81
|
+
def initialize(status_code, type, comment)
|
82
|
+
super(type, comment)
|
83
|
+
@status_code = status_code
|
84
|
+
end
|
85
|
+
|
86
|
+
def to_s
|
87
|
+
"#{@status_code}:#{super.to_s}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class TimeoutError < CieloError
|
92
|
+
def initialize(message)
|
93
|
+
super('TIMEOUT_ERROR', message)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
class ParsingError < CieloError
|
98
|
+
def initialize(message)
|
99
|
+
super('PARSING_ERROR', message)
|
100
|
+
end
|
101
|
+
end
|
75
102
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cielo24
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cielo24
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.2.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: tzinfo-data
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.2015.7
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.2015.7
|
69
83
|
description: This gem allows you to interact with the cielo24 public REST API.
|
70
84
|
email:
|
71
85
|
- support@cielo24.com
|
@@ -98,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
112
|
version: '0'
|
99
113
|
requirements: []
|
100
114
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.4.
|
115
|
+
rubygems_version: 2.4.5.1
|
102
116
|
signing_key:
|
103
117
|
specification_version: 4
|
104
118
|
summary: Cielo24 API gem.
|