reskribe_api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +53 -0
- data/Rakefile +7 -0
- data/lib/reskribe_api.rb +29 -0
- data/lib/reskribe_api/form.rb +12 -0
- data/lib/reskribe_api/request.rb +93 -0
- data/lib/reskribe_api/version.rb +3 -0
- data/reskribe_api.gemspec +24 -0
- data/spec/lib/reskribe_api_spec.rb +19 -0
- data/spec/spec_helper.rb +1 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7903f2be22989fda9189a7135267ff8451b4f8ac
|
4
|
+
data.tar.gz: cc5431ee230c9a9ec99df0b509ea95cfb17ca2b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7da4d7f3dfde7c30ac4e0ba7eb8330bbc80deff0fec65d93ffde4e6a963f17cc0af020c393e3d5ed1413c76719004a929b88fcff0fa3480377a9140bbc6dbbbc
|
7
|
+
data.tar.gz: e49c45edc7be8c8c149afd84346dbedd3c701a3850343fff547b700a2171fe131ca1fa1ec0ee8b27c219579779cb471738d09547307b937d840f4e4757c16131
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Esteban Uscanga
|
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,53 @@
|
|
1
|
+
# ReskribeApi
|
2
|
+
|
3
|
+
Ruby gem for accesing to Reskribe API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'reskribe_api'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install reskribe_api
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
The Reskribe API requires the api_token
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
ReskribeApi.api_token = "api_token_here"
|
25
|
+
```
|
26
|
+
|
27
|
+
Optional you can override to use ssl or not
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
ReskribeApi.ssl = false
|
31
|
+
```
|
32
|
+
|
33
|
+
Or the end point
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
ReskribeApi.api_base = "anotherReskribeEndPoint"
|
37
|
+
```
|
38
|
+
|
39
|
+
## Commands
|
40
|
+
|
41
|
+
### Forms
|
42
|
+
#### Create a Form
|
43
|
+
```ruby
|
44
|
+
ReskribeApi::Form.create("plan_name", "user_id")
|
45
|
+
```
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create new Pull Request :)
|
data/Rakefile
ADDED
data/lib/reskribe_api.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'uri'
|
3
|
+
require 'net/https'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
require 'reskribe_api/form'
|
7
|
+
require 'reskribe_api/version'
|
8
|
+
require 'reskribe_api/request'
|
9
|
+
|
10
|
+
module ReskribeApi
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :api_token
|
14
|
+
attr_accessor :ssl
|
15
|
+
attr_accessor :api_base
|
16
|
+
end
|
17
|
+
|
18
|
+
class Error < StandardError; end
|
19
|
+
|
20
|
+
module Errors
|
21
|
+
class ServiceUnavailable < Error; end
|
22
|
+
class AccessDenied < Error; end
|
23
|
+
class NotFound < Error; end
|
24
|
+
class CommunicationError < Error; end
|
25
|
+
class ValidationError < Error; end
|
26
|
+
class UnexpectedResponse < Error; end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module ReskribeApi
|
2
|
+
class Request
|
3
|
+
|
4
|
+
def self.request(path, method=:get, data = {})
|
5
|
+
req = self.new([path, 'api_token=' + ReskribeApi.api_token].join('?'), method)
|
6
|
+
req.data = data
|
7
|
+
req.make && req.success? ? req.output : false
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :path, :method
|
11
|
+
attr_accessor :data
|
12
|
+
|
13
|
+
def initialize(path, method = :get)
|
14
|
+
@path = path
|
15
|
+
@method = method
|
16
|
+
end
|
17
|
+
|
18
|
+
def success?
|
19
|
+
@success || false
|
20
|
+
end
|
21
|
+
|
22
|
+
def output
|
23
|
+
@output || nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def make
|
27
|
+
protocol = (ReskribeApi.ssl) ? 'https://' : 'http://'
|
28
|
+
path = (ReskribeApi.api_base) ? ReskribeApi.api_base : 'api.reskribe.com/v1'
|
29
|
+
|
30
|
+
uri = URI.parse([protocol + path, @path].join('/'))
|
31
|
+
|
32
|
+
http_request = http_class.new(uri.request_uri)
|
33
|
+
http_request.initialize_http_header({"User-Agent" => "ReskribeApiRubyClient/#{ReskribeApi::VERSION}"})
|
34
|
+
http_request.initialize_http_header({"Accept" => "application/json"})
|
35
|
+
http_request.content_type = "application/json"
|
36
|
+
|
37
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
38
|
+
|
39
|
+
if ReskribeApi.ssl
|
40
|
+
http.use_ssl = true
|
41
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
42
|
+
end
|
43
|
+
|
44
|
+
http_result = http.request(http_request, @data.to_json)
|
45
|
+
|
46
|
+
if http_result.body == 'true'
|
47
|
+
@output = true
|
48
|
+
elsif http_result.body == 'false'
|
49
|
+
@output = false
|
50
|
+
else
|
51
|
+
http_result.body ? @output = JSON_parse(http_result.body) : @output
|
52
|
+
end
|
53
|
+
|
54
|
+
@success = case http_result
|
55
|
+
when Net::HTTPSuccess
|
56
|
+
true
|
57
|
+
when Net::HTTPServiceUnavailable
|
58
|
+
raise ReskribeApi::Errors::ServiceUnavailable
|
59
|
+
when Net::HTTPForbidden, Net::HTTPUnauthorized
|
60
|
+
raise ReskribeApi::Errors::AccessDenied, "Access Denied"
|
61
|
+
when Net::HTTPNotFound
|
62
|
+
json = JSON_parse(http_result.body)
|
63
|
+
raise ReskribeApi::Errors::NotFound, json
|
64
|
+
when Net::HTTPBadRequest, Net::HTTPUnauthorized, Net::HTTPMethodNotAllowed
|
65
|
+
json = JSON_parse(http_result.body)
|
66
|
+
raise ReskribeApi::Errors::AccessDenied, "Access Denied: #{json}"
|
67
|
+
else
|
68
|
+
raise ReskribeApi::Errors::CommunicationError, http_result.body
|
69
|
+
end
|
70
|
+
self
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def JSON_parse json
|
76
|
+
return JSON.parse(json, :symbolize_names => true)
|
77
|
+
|
78
|
+
rescue JSON::ParserError
|
79
|
+
raise ReskribeApi::Errors::UnexpectedResponse, "Wrong JSON response"
|
80
|
+
end
|
81
|
+
|
82
|
+
def http_class
|
83
|
+
case @method
|
84
|
+
when :post then Net::HTTP::Post
|
85
|
+
when :put then Net::HTTP::Put
|
86
|
+
when :delete then Net::HTTP::Delete
|
87
|
+
else
|
88
|
+
Net::HTTP::Get
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'reskribe_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "reskribe_api"
|
8
|
+
spec.version = ReskribeApi::VERSION
|
9
|
+
spec.authors = ["Esteban Uscanga"]
|
10
|
+
spec.email = ["esteban@liquidlabs.de"]
|
11
|
+
spec.description = %q{Ruby gem for accesing to Reskribe API}
|
12
|
+
spec.summary = %q{Reskribe API Ruby Gem}
|
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
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ReskribeApi do
|
4
|
+
|
5
|
+
ReskribeApi.api_token = "75ez43hff2ggazi7m057xar4wtect0yguvfselpmp4-a9hiay6cpsoqrpiwlcejlww"
|
6
|
+
ReskribeApi.ssl = false
|
7
|
+
ReskribeApi.api_base = "api.rskr1.com/v1"
|
8
|
+
|
9
|
+
context "when Form is created" do
|
10
|
+
it "result should be not null" do
|
11
|
+
result = ReskribeApi::Form.create("testplan2", "new_uid1")
|
12
|
+
|
13
|
+
result[:url].should_not be_nil
|
14
|
+
result[:security_token].should_not be_nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'reskribe_api'
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reskribe_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Esteban Uscanga
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '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'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Ruby gem for accesing to Reskribe API
|
56
|
+
email:
|
57
|
+
- esteban@liquidlabs.de
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/reskribe_api.rb
|
68
|
+
- lib/reskribe_api/form.rb
|
69
|
+
- lib/reskribe_api/request.rb
|
70
|
+
- lib/reskribe_api/version.rb
|
71
|
+
- reskribe_api.gemspec
|
72
|
+
- spec/lib/reskribe_api_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: ''
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.1.9
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Reskribe API Ruby Gem
|
98
|
+
test_files:
|
99
|
+
- spec/lib/reskribe_api_spec.rb
|
100
|
+
- spec/spec_helper.rb
|