webcoder 0.0.1
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 +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/webcoder.rb +26 -0
- data/lib/webcoder/account.rb +21 -0
- data/lib/webcoder/errors.rb +45 -0
- data/lib/webcoder/http.rb +97 -0
- data/lib/webcoder/http/net_http.rb +122 -0
- data/lib/webcoder/http/resources/webcoder_ca_chain.crt +62 -0
- data/lib/webcoder/http/typhoeus.rb +31 -0
- data/lib/webcoder/input.rb +13 -0
- data/lib/webcoder/job.rb +34 -0
- data/lib/webcoder/notification.rb +13 -0
- data/lib/webcoder/output.rb +13 -0
- data/lib/webcoder/report.rb +9 -0
- data/lib/webcoder/resource.rb +76 -0
- data/lib/webcoder/response.rb +33 -0
- data/lib/webcoder/serializer.rb +35 -0
- data/lib/webcoder/upload.rb +8 -0
- data/lib/webcoder/version.rb +3 -0
- data/lib/webcoder/webcoder.rb +18 -0
- data/webcoder.gemspec +23 -0
- metadata +108 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 novikov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Webcoder
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'webcoder'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install webcoder
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/webcoder.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Standard Library
|
2
|
+
require 'cgi'
|
3
|
+
require 'net/https'
|
4
|
+
require 'timeout'
|
5
|
+
|
6
|
+
# JSON serialization
|
7
|
+
require 'multi_json'
|
8
|
+
|
9
|
+
# Webcoder
|
10
|
+
require 'webcoder/version'
|
11
|
+
require 'webcoder/serializer'
|
12
|
+
require 'webcoder/webcoder'
|
13
|
+
require 'webcoder/resource'
|
14
|
+
require 'webcoder/http/net_http'
|
15
|
+
require 'webcoder/http/typhoeus'
|
16
|
+
require 'webcoder/http'
|
17
|
+
require 'webcoder/errors'
|
18
|
+
require 'webcoder/report'
|
19
|
+
require 'webcoder/job'
|
20
|
+
require 'webcoder/input'
|
21
|
+
require 'webcoder/output'
|
22
|
+
require 'webcoder/account'
|
23
|
+
require 'webcoder/notification'
|
24
|
+
require 'webcoder/response'
|
25
|
+
require 'webcoder/upload'
|
26
|
+
require 'webcoder/version'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Webcoder
|
2
|
+
class Account < Resource
|
3
|
+
|
4
|
+
def self.create(params={}, options={})
|
5
|
+
post("/account", params, options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.details(options={})
|
9
|
+
get("/account", options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.integration(options={})
|
13
|
+
put("/account/integration", nil, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.live(options={})
|
17
|
+
put("/account/live", nil, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Webcoder
|
2
|
+
class Error < StandardError
|
3
|
+
|
4
|
+
def initialize(error_or_message)
|
5
|
+
if error_or_message.is_a?(Exception)
|
6
|
+
@error = error_or_message
|
7
|
+
else
|
8
|
+
@message = error_or_message
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def message
|
13
|
+
@message || "#{@error.class} (wrapped in a #{self.class}) - #{@error.message}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def backtrace
|
17
|
+
if @error
|
18
|
+
error_backtrace = ["--- Backtrace from #{@error.class} ---"] + (@error.backtrace || [])
|
19
|
+
wrapper_backtrace = ["--- Backtrace from #{self.class} ---"] + (super || [])
|
20
|
+
error_backtrace + wrapper_backtrace
|
21
|
+
else
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def inspect
|
27
|
+
if @error
|
28
|
+
"#{@error.inspect} (wrapped in a #{self.class})"
|
29
|
+
else
|
30
|
+
super
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
if @error
|
36
|
+
"#{@error.class} (wrapped in a #{self.class}) - #{@error}"
|
37
|
+
else
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class HTTPError < Error; end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Webcoder
|
2
|
+
class HTTP
|
3
|
+
|
4
|
+
CA_CHAIN_PATH = File.expand_path(File.join(File.dirname(__FILE__), "http", "resources", "webcoder_ca_chain.crt"))
|
5
|
+
|
6
|
+
include Webcoder::Serializer
|
7
|
+
|
8
|
+
attr_accessor :url, :options, :method
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :default_options, :http_backend
|
12
|
+
end
|
13
|
+
|
14
|
+
self.http_backend = NetHTTP
|
15
|
+
|
16
|
+
self.default_options = {:timeout => 60000,
|
17
|
+
:headers => {'Accept' => 'application/json',
|
18
|
+
'Content-Type' => 'application/json',
|
19
|
+
'User-Agent' => "Webcoder v#{Webcoder::VERSION}"}}
|
20
|
+
|
21
|
+
def initialize(method, url, options={})
|
22
|
+
self.method = method
|
23
|
+
self.url = url
|
24
|
+
self.options = options
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.post(url, body, options={})
|
28
|
+
new(:post, url, options.merge(:body => body)).perform_method
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.put(url, body, options={})
|
32
|
+
new(:put, url, options.merge(:body => body)).perform_method
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.get(url, options={})
|
36
|
+
new(:get, url, options).perform_method
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.delete(url, options={})
|
40
|
+
new(:delete, url, options).perform_method
|
41
|
+
end
|
42
|
+
|
43
|
+
def perform_method
|
44
|
+
process(http_backend.send(method, url, options))
|
45
|
+
rescue StandardError => e
|
46
|
+
raise HTTPError.new(e)
|
47
|
+
end
|
48
|
+
|
49
|
+
def options=(value)
|
50
|
+
value ||= {}
|
51
|
+
|
52
|
+
# Hacky, deeper hash merge
|
53
|
+
default_options.keys.each do |key|
|
54
|
+
if value.has_key?(key)
|
55
|
+
if value[key].is_a?(Hash) && default_options[key].is_a?(Hash)
|
56
|
+
value[key] = default_options[key].merge(value[key])
|
57
|
+
end
|
58
|
+
else
|
59
|
+
value[key] = default_options[key]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
@options = value
|
64
|
+
end
|
65
|
+
|
66
|
+
def options
|
67
|
+
@options || self.options = default_options
|
68
|
+
end
|
69
|
+
|
70
|
+
def http_backend
|
71
|
+
self.class.http_backend
|
72
|
+
end
|
73
|
+
|
74
|
+
def default_options
|
75
|
+
self.class.default_options
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
protected
|
80
|
+
|
81
|
+
def process(http_response)
|
82
|
+
response = Response.new
|
83
|
+
response.code = http_response.code
|
84
|
+
|
85
|
+
begin
|
86
|
+
response.body = decode(http_response.body.to_s)
|
87
|
+
rescue StandardError # Hack! Returns different exceptions depending on the decoding engine
|
88
|
+
response.body = http_response.body
|
89
|
+
end
|
90
|
+
|
91
|
+
response.raw_body = http_response.body
|
92
|
+
response.raw_response = http_response
|
93
|
+
response
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module Webcoder
|
2
|
+
class HTTP
|
3
|
+
class NetHTTP
|
4
|
+
|
5
|
+
attr_accessor :method, :url, :uri, :body, :params, :headers, :timeout, :skip_ssl_verify, :options
|
6
|
+
|
7
|
+
def initialize(method, url, options)
|
8
|
+
@method = method
|
9
|
+
@url = url
|
10
|
+
@body = options.delete(:body)
|
11
|
+
@params = options.delete(:params)
|
12
|
+
@headers = options.delete(:headers)
|
13
|
+
@timeout = options.delete(:timeout)
|
14
|
+
@skip_ssl_verify = options.delete(:skip_ssl_verify)
|
15
|
+
@options = options
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.post(url, options={})
|
19
|
+
new(:post, url, options).perform
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.put(url, options={})
|
23
|
+
new(:put, url, options).perform
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.get(url, options={})
|
27
|
+
new(:get, url, options).perform
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.delete(url, options={})
|
31
|
+
new(:delete, url, options).perform
|
32
|
+
end
|
33
|
+
|
34
|
+
def perform
|
35
|
+
deliver(http, request)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def deliver(http, request)
|
42
|
+
if timeout
|
43
|
+
Timeout.timeout(timeout / 1000.0) do
|
44
|
+
http.request(request)
|
45
|
+
end
|
46
|
+
else
|
47
|
+
http.request(request)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def http
|
52
|
+
u = uri
|
53
|
+
|
54
|
+
http = Net::HTTP.new(u.host, u.port)
|
55
|
+
|
56
|
+
if u.scheme == 'https'
|
57
|
+
http.use_ssl = true
|
58
|
+
|
59
|
+
if skip_ssl_verify
|
60
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
61
|
+
else
|
62
|
+
http.ca_file = Webcoder::HTTP::CA_CHAIN_PATH
|
63
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
64
|
+
http.verify_depth = 5
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
http
|
69
|
+
end
|
70
|
+
|
71
|
+
def request
|
72
|
+
r = request_class.new(path)
|
73
|
+
if body
|
74
|
+
r.body = body
|
75
|
+
elsif [:post, :put].include?(@method)
|
76
|
+
r.body = ""
|
77
|
+
end
|
78
|
+
|
79
|
+
if headers
|
80
|
+
headers.each do |header, value|
|
81
|
+
r.add_field(header.to_s, value.to_s)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
r
|
85
|
+
end
|
86
|
+
|
87
|
+
def uri
|
88
|
+
u = URI.parse(url)
|
89
|
+
|
90
|
+
if params
|
91
|
+
params_as_query = params.map{|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"}.join('&')
|
92
|
+
if u.query.to_s.empty?
|
93
|
+
u.query = params_as_query
|
94
|
+
else
|
95
|
+
u.query = [u.query.to_s, params_as_query].join('&')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
u
|
100
|
+
end
|
101
|
+
|
102
|
+
def path
|
103
|
+
u = uri
|
104
|
+
|
105
|
+
if u.path.empty?
|
106
|
+
u.path = '/'
|
107
|
+
end
|
108
|
+
|
109
|
+
if u.query.to_s.empty?
|
110
|
+
u.path
|
111
|
+
else
|
112
|
+
u.path + '?' + u.query.to_s
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def request_class
|
117
|
+
Net::HTTP.const_get(method.to_s.capitalize)
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDJzCCApCgAwIBAgIBATANBgkqhkiG9w0BAQQFADCBzjELMAkGA1UEBhMCWkEx
|
3
|
+
FTATBgNVBAgTDFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZSBUb3duMR0wGwYD
|
4
|
+
VQQKExRUaGF3dGUgQ29uc3VsdGluZyBjYzEoMCYGA1UECxMfQ2VydGlmaWNhdGlv
|
5
|
+
biBTZXJ2aWNlcyBEaXZpc2lvbjEhMB8GA1UEAxMYVGhhd3RlIFByZW1pdW0gU2Vy
|
6
|
+
dmVyIENBMSgwJgYJKoZIhvcNAQkBFhlwcmVtaXVtLXNlcnZlckB0aGF3dGUuY29t
|
7
|
+
MB4XDTk2MDgwMTAwMDAwMFoXDTI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DVQQLEx5HVEUgQ3liZXJU
|
54
|
+
cnVzdCBTb2x1dGlvbnMsIEluYy4xIzAhBgNVBAMTGkdURSBDeWJlclRydXN0IEds
|
55
|
+
b2JhbCBSb290MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCVD6C28FCc6HrH
|
56
|
+
iM3dFw4usJTQGz0O9pTAipTHBsiQl8i4ZBp6fmw8U+E3KHNgf7KXUwefU/ltWJTS
|
57
|
+
r41tiGeA5u2ylc9yMcqlHHK6XALnZELn+aks1joNrI1CqiQBOeacPwGFVw1Yh0X4
|
58
|
+
04Wqk2kmhXBIgD8SFcd5tB8FLztimQIDAQABMA0GCSqGSIb3DQEBBAUAA4GBAG3r
|
59
|
+
GwnpXtlR22ciYaQqPEh346B8pt5zohQDhT37qw4wxYMWM4ETCJ57NE7fQMh017l9
|
60
|
+
3PR2VX2bY1QY6fDq81yx2YtCHrnAlU66+tXifPVoYb+O7AWXX1uw16OFNMQkpw0P
|
61
|
+
lZPvy5TYnh+dXIVtx6quTx8itc2VrbqnzPmrC3p/
|
62
|
+
-----END CERTIFICATE-----
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Webcoder
|
2
|
+
class HTTP
|
3
|
+
class Typhoeus
|
4
|
+
|
5
|
+
def self.post(url, options={})
|
6
|
+
perform(:post, url, options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.put(url, options={})
|
10
|
+
perform(:put, url, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.get(url, options={})
|
14
|
+
perform(:get, url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.delete(url, options={})
|
18
|
+
perform(:delete, url, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.perform(method, url, options={})
|
22
|
+
if options.delete(:skip_ssl_verify)
|
23
|
+
options[:disable_ssl_peer_verification] = true
|
24
|
+
end
|
25
|
+
|
26
|
+
::Typhoeus::Request.send(method, url, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/webcoder/job.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Webcoder
|
2
|
+
class Job < Resource
|
3
|
+
|
4
|
+
def self.create(params={}, options={})
|
5
|
+
post("/jobs", params, options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.list(options={})
|
9
|
+
options = options.dup
|
10
|
+
params = { :page => options.delete(:page) || 1,
|
11
|
+
:per_page => options.delete(:per_page) || 50,
|
12
|
+
:state => options.delete(:state) }
|
13
|
+
|
14
|
+
get("/jobs", merge_params(options, params))
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.details(job_id, options={})
|
18
|
+
get("/jobs/#{job_id}", options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.progress(job_id, options={})
|
22
|
+
get("/jobs/#{job_id}/progress", options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.resubmit(job_id, options={})
|
26
|
+
put("/jobs/#{job_id}/resubmit", nil, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.cancel(job_id, options={})
|
30
|
+
put("/jobs/#{job_id}/cancel", nil, options)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Webcoder
|
2
|
+
class Notification < Resource
|
3
|
+
|
4
|
+
def self.list(options={})
|
5
|
+
options = options.dup
|
6
|
+
params = {:page => options.delete(:page) || 1,
|
7
|
+
:per_page => options.delete(:per_page) || 50 }
|
8
|
+
|
9
|
+
get("/notifications", merge_params(options, params))
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Webcoder
|
2
|
+
class Resource
|
3
|
+
|
4
|
+
include Webcoder::Serializer
|
5
|
+
|
6
|
+
def self.api_key
|
7
|
+
Webcoder.api_key
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.base_url
|
11
|
+
Webcoder.base_url
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.post(path, params={}, options={})
|
15
|
+
options = options.dup
|
16
|
+
url = url_for(path, options)
|
17
|
+
body = encode(params)
|
18
|
+
options = add_api_key_header(options)
|
19
|
+
HTTP.post(url, body, options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.put(path, params={}, options={})
|
23
|
+
options = options.dup
|
24
|
+
url = url_for(path, options)
|
25
|
+
body = encode(params)
|
26
|
+
options = add_api_key_header(options)
|
27
|
+
HTTP.put(url, body, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get(path, options={})
|
31
|
+
options = options.dup
|
32
|
+
url = url_for(path, options)
|
33
|
+
options = add_api_key_header(options)
|
34
|
+
HTTP.get(url, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.delete(path, options={})
|
38
|
+
options = options.dup
|
39
|
+
url = url_for(path)
|
40
|
+
options = add_api_key_header(options)
|
41
|
+
HTTP.delete(url, options)
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def self.url_for(path, options={})
|
48
|
+
File.join((options[:base_url] || base_url).to_s, path.to_s)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.add_api_key_header(options)
|
52
|
+
effective_api_key = options.delete(:api_key) || api_key
|
53
|
+
|
54
|
+
if effective_api_key
|
55
|
+
if options[:headers]
|
56
|
+
options[:headers] = options[:headers].dup
|
57
|
+
else
|
58
|
+
options[:headers] = {}
|
59
|
+
end
|
60
|
+
options[:headers]["Webcoder-Api-Key"] = effective_api_key
|
61
|
+
end
|
62
|
+
|
63
|
+
options
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.merge_params(options, params)
|
67
|
+
if options[:params]
|
68
|
+
options[:params] = options[:params].merge(params)
|
69
|
+
options
|
70
|
+
else
|
71
|
+
options.merge(:params => params)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Webcoder
|
2
|
+
class Response
|
3
|
+
|
4
|
+
attr_accessor :code, :body, :raw_body, :raw_response
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
options.each do |k, v|
|
8
|
+
send("#{k}=", v) if respond_to?("#{k}=")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def success?
|
13
|
+
code.to_i > 199 && code.to_i < 300
|
14
|
+
end
|
15
|
+
|
16
|
+
def errors
|
17
|
+
if body.is_a?(Hash)
|
18
|
+
Array(body['errors']).compact
|
19
|
+
else
|
20
|
+
[]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def body_without_wrapper
|
25
|
+
if body.is_a?(Hash) && body['api_response']
|
26
|
+
body['api_response']
|
27
|
+
else
|
28
|
+
body
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Webcoder
|
2
|
+
module Serializer
|
3
|
+
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def self.included(klass)
|
7
|
+
klass.extend(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def encode(content)
|
11
|
+
if content.is_a?(String) || content.nil?
|
12
|
+
content
|
13
|
+
else
|
14
|
+
if MultiJson.respond_to?(:dump)
|
15
|
+
MultiJson.dump(content)
|
16
|
+
else
|
17
|
+
MultiJson.encode(content)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def decode(content)
|
23
|
+
if content.is_a?(String)
|
24
|
+
if MultiJson.respond_to?(:dump)
|
25
|
+
MultiJson.load(content)
|
26
|
+
else
|
27
|
+
MultiJson.decode(content)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
content
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Webcoder
|
2
|
+
|
3
|
+
class << self
|
4
|
+
attr_accessor :api_key, :base_url
|
5
|
+
end
|
6
|
+
|
7
|
+
self.api_key = nil
|
8
|
+
self.base_url = 'https://app.webcoder.com/api/v2'
|
9
|
+
|
10
|
+
def self.api_key
|
11
|
+
@api_key || ENV['WEBCODER_API_KEY']
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.base_url(env=nil)
|
15
|
+
@base_url
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/webcoder.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'webcoder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "webcoder"
|
8
|
+
spec.version = Webcoder::VERSION
|
9
|
+
spec.authors = ["novikov"]
|
10
|
+
spec.email = ["novikov@inventos.ru"]
|
11
|
+
spec.description = %q{}
|
12
|
+
spec.summary = %q{Simple wrapper for Webcoder API}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webcoder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- novikov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: ''
|
47
|
+
email:
|
48
|
+
- novikov@inventos.ru
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/webcoder.rb
|
59
|
+
- lib/webcoder/account.rb
|
60
|
+
- lib/webcoder/errors.rb
|
61
|
+
- lib/webcoder/http.rb
|
62
|
+
- lib/webcoder/http/net_http.rb
|
63
|
+
- lib/webcoder/http/resources/webcoder_ca_chain.crt
|
64
|
+
- lib/webcoder/http/typhoeus.rb
|
65
|
+
- lib/webcoder/input.rb
|
66
|
+
- lib/webcoder/job.rb
|
67
|
+
- lib/webcoder/notification.rb
|
68
|
+
- lib/webcoder/output.rb
|
69
|
+
- lib/webcoder/report.rb
|
70
|
+
- lib/webcoder/resource.rb
|
71
|
+
- lib/webcoder/response.rb
|
72
|
+
- lib/webcoder/serializer.rb
|
73
|
+
- lib/webcoder/upload.rb
|
74
|
+
- lib/webcoder/version.rb
|
75
|
+
- lib/webcoder/webcoder.rb
|
76
|
+
- webcoder.gemspec
|
77
|
+
homepage: ''
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
hash: 3063039980127814060
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
hash: 3063039980127814060
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.8.25
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Simple wrapper for Webcoder API
|
108
|
+
test_files: []
|