authorr-api 1.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.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +34 -0
- data/Rakefile +2 -0
- data/authorr-api.gemspec +17 -0
- data/lib/authorr-api.rb +4 -0
- data/lib/authorr-api/customers.rb +147 -0
- data/lib/authorr-api/version.rb +5 -0
- metadata +53 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MjcwMWM5Y2MxMGViN2MxNWUzNWRiNTMyM2Q5Y2MzMzE1ZTI3MmIyNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NDI1NDU1OWI3M2ZiNDE3NTQ4MjE5NDU4NTU0MDg0N2U0MzVmZTQ0YQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZWQ2OTI1Zjc0ODNjNDE4YTg4NjE4OTA3NGU2NTlkNzA1NmFhNjgzNWEyY2My
|
10
|
+
ZGI1NGFjYzI0MDhjY2UwNzc0ZjU2ZDk0OWRlN2MwZWJiNDZmYWRkNDgyOWY4
|
11
|
+
YmU5MzcwYmY4YmJkZDEwZTE3OGI4OTdmYjQxYTliZWM5NTliMjU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MGYzYjMxMDgzOWI0MzRjNmVmN2JkMDRkMDFiY2FmODc3YTQ0ZDczNjMxNWFm
|
14
|
+
OTM2YTcyMzNhOTE4MDRjOWFiNDNjMWVjYmI1NjU3MWQxZjFjMmZjZTc2Yzdj
|
15
|
+
N2UxMGNhMGY1MWNjZDc4YTE1NjQ2Zjg2MWVjMTEzYmVhZTA0NmU=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Velluto
|
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,34 @@
|
|
1
|
+
# Authorr API
|
2
|
+
|
3
|
+
This library is used to access The Authorr API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'authorr-api'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install authorr-api
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Include the gem on your project and use it like this:
|
22
|
+
|
23
|
+
require 'authorr-api'
|
24
|
+
|
25
|
+
api = AuthorrCustomer.new('<api_key>')
|
26
|
+
api.desired_method
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/authorr-api.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/authorr-api/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Velluto"]
|
6
|
+
gem.email = ["authorr@authorr.com"]
|
7
|
+
gem.description = %q{Authorr API for Customers and Authors}
|
8
|
+
gem.summary = %q{Authorr API}
|
9
|
+
gem.homepage = "http://www.authorr.com"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "authorr-api"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Authorr::Api::VERSION
|
17
|
+
end
|
data/lib/authorr-api.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
class AuthorrCustomer
|
7
|
+
class AuthorrCustomerException < RuntimeError
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(api_key, base_path = nil)
|
11
|
+
@base_path = base_path || 'http://app.authorr.com'
|
12
|
+
@api_key = api_key
|
13
|
+
end
|
14
|
+
|
15
|
+
def exec_get(uri)
|
16
|
+
uri = URI(uri)
|
17
|
+
result = Net::HTTP.get_response(uri)
|
18
|
+
if result.is_a?(Net::HTTPSuccess)
|
19
|
+
JSON.parse(result.body)
|
20
|
+
else
|
21
|
+
raise AuthorrCustomerException.new result.body
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def exec_post(parameters, method, uri)
|
26
|
+
uri = URI(uri)
|
27
|
+
req = case method
|
28
|
+
when 'put'
|
29
|
+
Net::HTTP::Put.new(uri.request_uri)
|
30
|
+
when 'post'
|
31
|
+
Net::HTTP::Post.new(uri.request_uri)
|
32
|
+
when 'delete'
|
33
|
+
Net::HTTP::Delete.new(uri.request_uri)
|
34
|
+
end
|
35
|
+
req.body = JSON.dump(parameters)
|
36
|
+
req.content_type = "application/json"
|
37
|
+
result = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
38
|
+
http.request(req)
|
39
|
+
end
|
40
|
+
#result = Net::HTTP.post_form(uri, converted_params)
|
41
|
+
if result.is_a?(Net::HTTPSuccess)
|
42
|
+
if result.body == 'false'
|
43
|
+
false
|
44
|
+
elsif result.body == 'true'
|
45
|
+
true
|
46
|
+
else
|
47
|
+
if method != 'delete'
|
48
|
+
JSON.parse(result.body)
|
49
|
+
else
|
50
|
+
result.body
|
51
|
+
end
|
52
|
+
end
|
53
|
+
else
|
54
|
+
raise AuthorrCustomerException.new result.body
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
# This method creates a new Order.
|
60
|
+
# Parameters:
|
61
|
+
# - assignments: List of assignments
|
62
|
+
# - min_rating: Minimum rating for author
|
63
|
+
# - name:
|
64
|
+
def create_order(assignments, min_rating = nil, name = nil)
|
65
|
+
if assignments.nil?
|
66
|
+
raise AuthorrCustomerException.new('assignments should not be empty')
|
67
|
+
end
|
68
|
+
parameters = {'order' => {'assignments' => assignments, 'min_rating' => min_rating, 'name' => name}}
|
69
|
+
exec_post(parameters, 'post', "#{@base_path}/api/v1/customers/orders.json?api_key=#{@api_key}")
|
70
|
+
end
|
71
|
+
|
72
|
+
# This method returns all your orders.
|
73
|
+
# Parameters:
|
74
|
+
# none
|
75
|
+
def get_orders()
|
76
|
+
exec_get("#{@base_path}/api/v1/customers/orders.json?api_key=#{@api_key}")
|
77
|
+
end
|
78
|
+
|
79
|
+
# Returns the details of a specific order. Use this to check the status of your orders.
|
80
|
+
# Parameters:
|
81
|
+
# - id: Order ID
|
82
|
+
def get_order_by_id(id)
|
83
|
+
if id.nil?
|
84
|
+
raise AuthorrCustomerException.new('id should not be empty')
|
85
|
+
end
|
86
|
+
exec_get("#{@base_path}/api/v1/customers/orders/#{id}.json?api_key=#{@api_key}")
|
87
|
+
end
|
88
|
+
|
89
|
+
# Retrieves information about a single assignment.
|
90
|
+
# Parameters:
|
91
|
+
# - id: Assignment ID
|
92
|
+
def get_assignment_by_id(id)
|
93
|
+
if id.nil?
|
94
|
+
raise AuthorrCustomerException.new('id should not be empty')
|
95
|
+
end
|
96
|
+
exec_get("#{@base_path}/api/v1/customers/assignments/#{id}.json?api_key=#{@api_key}")
|
97
|
+
end
|
98
|
+
|
99
|
+
# Use this method to resubmit a rejected assignment. You should provide instructions along with your request
|
100
|
+
# for the author.
|
101
|
+
# Parameters:
|
102
|
+
# - id: Assignment ID
|
103
|
+
# - instructions: Instructions for Author
|
104
|
+
# - topic: Topic to write about
|
105
|
+
# - required_words_for_title: Required Words for Title (space separated)
|
106
|
+
# - required_keywords: Required Keywords (comma separated)
|
107
|
+
def resubmit_assignment(id, instructions, topic = nil, required_words_for_title = nil, required_keywords = nil)
|
108
|
+
if id.nil?
|
109
|
+
raise AuthorrCustomerException.new('id should not be empty')
|
110
|
+
end
|
111
|
+
|
112
|
+
if instructions.nil?
|
113
|
+
raise AuthorrCustomerException.new('instructions should not be empty')
|
114
|
+
end
|
115
|
+
parameters = {'instructions' => instructions, 'topic' => topic, 'required_words_for_title' => required_words_for_title, 'required_keywords' => required_keywords}
|
116
|
+
exec_post(parameters, 'put', "#{@base_path}/api/v1/customers/assignments/#{id}/resubmit.json?api_key=#{@api_key}")
|
117
|
+
end
|
118
|
+
|
119
|
+
# Use this method to request an edit to a delivered assignment. You should provide instructions along with your request
|
120
|
+
# for the author.
|
121
|
+
# Parameters:
|
122
|
+
# - id: Assignment ID
|
123
|
+
# - instructions: Edit instructions for the author
|
124
|
+
def request_assignment_edit(id, instructions)
|
125
|
+
if id.nil?
|
126
|
+
raise AuthorrCustomerException.new('id should not be empty')
|
127
|
+
end
|
128
|
+
|
129
|
+
if instructions.nil?
|
130
|
+
raise AuthorrCustomerException.new('instructions should not be empty')
|
131
|
+
end
|
132
|
+
parameters = {'instructions' => instructions}
|
133
|
+
exec_post(parameters, 'put', "#{@base_path}/api/v1/customers/assignments/#{id}/request_edit.json?api_key=#{@api_key}")
|
134
|
+
end
|
135
|
+
|
136
|
+
# Use this method to accept an assignment.
|
137
|
+
# Parameters:
|
138
|
+
# - id: Assignment ID
|
139
|
+
def accept_assignment(id)
|
140
|
+
if id.nil?
|
141
|
+
raise AuthorrCustomerException.new('id should not be empty')
|
142
|
+
end
|
143
|
+
parameters = {}
|
144
|
+
exec_post(parameters, 'put', "#{@base_path}/api/v1/customers/assignments/#{id}/accept_assignment.json?api_key=#{@api_key}")
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: authorr-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Velluto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Authorr API for Customers and Authors
|
14
|
+
email:
|
15
|
+
- authorr@authorr.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .gitignore
|
21
|
+
- Gemfile
|
22
|
+
- LICENSE
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- authorr-api.gemspec
|
26
|
+
- lib/authorr-api.rb
|
27
|
+
- lib/authorr-api/customers.rb
|
28
|
+
- lib/authorr-api/version.rb
|
29
|
+
homepage: http://www.authorr.com
|
30
|
+
licenses: []
|
31
|
+
metadata: {}
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 2.2.2
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: Authorr API
|
52
|
+
test_files: []
|
53
|
+
has_rdoc:
|