adn 0.0.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -5
- data/.travis.yml +7 -0
- data/Gemfile +6 -3
- data/Gemfile.lock +18 -0
- data/README.md +54 -17
- data/Rakefile +23 -1
- data/adn.gemspec +13 -13
- data/lib/adn/api/filter.rb +10 -0
- data/lib/adn/api/post.rb +47 -0
- data/lib/adn/api/response.rb +13 -0
- data/lib/adn/api/stream.rb +10 -0
- data/lib/adn/api/subscription.rb +11 -0
- data/lib/adn/api/token.rb +12 -0
- data/lib/adn/api/user.rb +23 -0
- data/lib/adn/api.rb +45 -0
- data/lib/adn/constants.rb +14 -0
- data/lib/adn/post.rb +62 -0
- data/lib/adn/user.rb +109 -0
- data/lib/adn/version.rb +8 -2
- data/lib/adn.rb +52 -3
- data/spec/adn/api/filter_spec.rb +9 -0
- data/spec/adn/api/post_spec.rb +103 -0
- data/spec/adn/api/response_spec.rb +13 -0
- data/spec/adn/api/stream_spec.rb +9 -0
- data/spec/adn/api/subscription_spec.rb +9 -0
- data/spec/adn/api/token_spec.rb +21 -0
- data/spec/adn/api/user_spec.rb +35 -0
- data/spec/adn/post_spec.rb +146 -0
- data/spec/adn/user_spec.rb +117 -0
- data/spec/adn_spec.rb +40 -0
- data/spec/fixtures/post.json +88 -0
- data/spec/fixtures/user.json +54 -0
- data/spec/spec_helper.rb +30 -0
- metadata +56 -11
- data/LICENSE +0 -22
data/.gitignore
CHANGED
@@ -2,12 +2,8 @@
|
|
2
2
|
*.rbc
|
3
3
|
.bundle
|
4
4
|
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
5
|
coverage
|
10
|
-
|
6
|
+
InstalledFiles
|
11
7
|
lib/bundler/man
|
12
8
|
pkg
|
13
9
|
rdoc
|
@@ -15,3 +11,8 @@ spec/reports
|
|
15
11
|
test/tmp
|
16
12
|
test/version_tmp
|
17
13
|
tmp
|
14
|
+
|
15
|
+
# YARD artifacts
|
16
|
+
.yardoc
|
17
|
+
_yardoc
|
18
|
+
doc/
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
data/README.md
CHANGED
@@ -1,29 +1,66 @@
|
|
1
|
-
|
1
|
+
ADN
|
2
|
+
===
|
2
3
|
|
3
|
-
|
4
|
+
[![Build Status](https://secure.travis-ci.org/kishyr/ADNRuby.png)](http://travis-ci.org/kishyr/ADNRuby)
|
4
5
|
|
5
|
-
|
6
|
+
A Ruby library for App.net by [@kishyr](https://alpha.app.net/kishyr).
|
6
7
|
|
7
|
-
|
8
|
+
This library follows the current [App.net API Spec](https://github.com/appdotnet/api-spec) (as at 26 August 2012).
|
8
9
|
|
9
|
-
|
10
|
+
### Contributors
|
10
11
|
|
11
|
-
|
12
|
+
ADN is brought to you by these very handsome gentlemen:
|
12
13
|
|
13
|
-
|
14
|
+
* Kishyr Ramdial ([@kishyr](https://alpha.app.net/kishyr))
|
15
|
+
* Dave Goodchild ([@buddhamagnet](https://alpha.app.net/buddhamagnet))
|
16
|
+
* Peter Hellberg ([@peterhellberg](https://alpha.app.net/peterhellberg))
|
14
17
|
|
15
|
-
|
18
|
+
### Installation
|
16
19
|
|
17
|
-
|
20
|
+
Simply add ADN to your Gemfile:
|
18
21
|
|
19
|
-
|
22
|
+
`gem "adn"`
|
20
23
|
|
21
|
-
|
24
|
+
Or you can install ADN directly from rubygems.org:
|
22
25
|
|
23
|
-
|
26
|
+
`gem install adn`
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
### Usage
|
29
|
+
For API calls that accept parameters described in the App.net API Spec, simply pass them as a dictionary to the method.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'adn'
|
33
|
+
|
34
|
+
ADN.token = "your App.net OAuth-token here."
|
35
|
+
|
36
|
+
# TODO: Actually describe the usage of the library
|
37
|
+
# (Should be refactored first)
|
38
|
+
```
|
39
|
+
|
40
|
+
Complete documentation will be available soon, but in the meantime you can browse all API methods in `lib/adnruby.rb`.
|
41
|
+
|
42
|
+
### Changelog
|
43
|
+
|
44
|
+
* **Version 0.3.1** (28 August 2012)
|
45
|
+
* Fixed naming conflict
|
46
|
+
* **Version 0.3** (28 August 2012)
|
47
|
+
* Now includes a Post class that describes each post along with a bunch of new methods of accessing a post's replies and the post's original post.
|
48
|
+
* Users methods that return user details (follow, unfollow, following, followers, mute, unmute, mute_list) will now return either a User object back, or an array of User objects.
|
49
|
+
* Similarly, User methods that return post details (posts, mentions, stream) will return a Post object, or an array of Post objects.
|
50
|
+
* To accomplish all this, I've had to change the module structure which will break existing code if you've relied on the modules to access any data. Basically, all modules begin with ADN::API:: now (eg. ADN::API::Post, ADN::API::User).
|
51
|
+
* **Version 0.2** (27 August 2012)
|
52
|
+
* Changed all existing classes to modules and introduced the User class for easily accessing user details
|
53
|
+
* **Version 0.1** (26 August 2012)
|
54
|
+
* Really basic functionality for all existing App.new API methods as per the spec.
|
55
|
+
|
56
|
+
---
|
57
|
+
|
58
|
+
### License
|
59
|
+
|
60
|
+
**ADN** is licensed under the MIT License and is Copyright (c) 2012 Kishyr Ramdial.
|
61
|
+
|
62
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
63
|
+
|
64
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
65
|
+
|
66
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -1,2 +1,24 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require
|
2
|
+
require 'find'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
|
6
|
+
task :default => :spec
|
7
|
+
|
8
|
+
Rake::TestTask.new(:spec) do |t|
|
9
|
+
t.test_files = FileList['spec/**/*_spec.rb']
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Run cane to check quality metrics"
|
13
|
+
task :quality do
|
14
|
+
Bundler.with_clean_env do
|
15
|
+
exec 'cane'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "Run tests in a loop using kicker (>= 3.0.0pre1)"
|
20
|
+
task :kicker do
|
21
|
+
Bundler.with_clean_env do
|
22
|
+
exec 'kicker --no-notification -r ruby -e "clear && rake" spec lib'
|
23
|
+
end
|
24
|
+
end
|
data/adn.gemspec
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
2
3
|
require File.expand_path('../lib/adn/version', __FILE__)
|
3
4
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'adn'
|
7
|
+
s.version = ADN::VERSION
|
8
|
+
s.authors = ["Kishyr Ramdial", "Dave Goodchild", "Peter Hellberg"]
|
9
|
+
s.email = ["kishyr@gmail.com", "buddhamagnet@gmail.com", "peter@c7.se"]
|
10
|
+
s.description = "A simple and easy to use library to interact with App.net's API"
|
11
|
+
s.summary = "A Ruby library for App.net"
|
12
|
+
s.homepage = "https://github.com/kishyr/ADNRuby"
|
13
|
+
s.files = `git ls-files`.split($\)
|
14
|
+
s.test_files = s.files.grep(%r{^(spec)/})
|
10
15
|
|
11
|
-
|
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 = "adn"
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = Adn::VERSION
|
16
|
+
s.required_ruby_version = '>= 1.9.3'
|
17
17
|
end
|
data/lib/adn/api/post.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module ADN
|
4
|
+
module API
|
5
|
+
module Post
|
6
|
+
def self.create(params)
|
7
|
+
ADN::API.post("#{ADN::API_ENDPOINT_POSTS}", params)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.retrieve(post_id)
|
11
|
+
ADN::API.get("#{ADN::API_ENDPOINT_POSTS}/#{post_id}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.by_id(post_id)
|
15
|
+
self.retrieve(post_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.delete(post_id)
|
19
|
+
ADN::API.delete("#{ADN::API_ENDPOINT_POSTS}/#{post_id}")
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.replies(post_id, params = nil)
|
23
|
+
ADN::API.get("#{ADN::API_ENDPOINT_POSTS}/#{post_id}/replies", params)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.by_user(user_id, params = nil)
|
27
|
+
ADN::API.get("#{ADN::API_ENDPOINT_USERS}/#{user_id}/posts", params)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.mentioning_user(user_id, params = nil)
|
31
|
+
ADN::API.get("#{ADN::API_ENDPOINT_USERS}/#{user_id}/mentions", params)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.stream(params = nil)
|
35
|
+
ADN::API.get("#{ADN::API_ENDPOINT_POSTS}/stream", params)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.global_stream(params = nil)
|
39
|
+
ADN::API.get("#{ADN::API_ENDPOINT_POSTS}/stream/global", params)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.by_hashtag(hashtag, params = nil)
|
43
|
+
ADN::API.get("#{ADN::API_ENDPOINT_POSTS}/tag/#{hashtag}", params)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/adn/api/user.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module ADN
|
4
|
+
module API
|
5
|
+
module User
|
6
|
+
def self.retrieve(user_id)
|
7
|
+
ADN::API.get("#{ADN::API_ENDPOINT_USERS}/#{user_id}")
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.by_id(user_id)
|
11
|
+
self.retrieve(user_id)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.following(user_id)
|
15
|
+
ADN::API.get("#{ADN::API_ENDPOINT_USERS}/#{user_id}/following")
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.followers(user_id)
|
19
|
+
ADN::API.get("#{ADN::API_ENDPOINT_USERS}/#{user_id}/followers")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/adn/api.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
%w{response filter post stream subscription token user}.each do |f|
|
4
|
+
require_relative "api/#{f}"
|
5
|
+
end
|
6
|
+
|
7
|
+
module ADN
|
8
|
+
module API
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def perform(request)
|
13
|
+
request.add_field("Authorization", "Bearer #{ADN.token}")
|
14
|
+
response = JSON.parse ADN::HTTP.request(request).body
|
15
|
+
|
16
|
+
Response.new(response).tap { |r|
|
17
|
+
raise ADN::API::Error, r['error'] if r.has_error?
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(url, params = nil)
|
22
|
+
url = params.nil? ? url : [url, URL.encode_www_form(params)].join("?")
|
23
|
+
request = Net::HTTP::Get.new(url)
|
24
|
+
perform(request)
|
25
|
+
end
|
26
|
+
|
27
|
+
def post(url, params = nil)
|
28
|
+
request = Net::HTTP::Post.new(url)
|
29
|
+
request.set_form_data(params) if params
|
30
|
+
perform(request)
|
31
|
+
end
|
32
|
+
|
33
|
+
def put(url, params = nil)
|
34
|
+
request = Net::HTTP::Put.new(url)
|
35
|
+
request.set_form_data(params) if params
|
36
|
+
perform(request)
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete(url)
|
40
|
+
request = Net::HTTP::Delete.new(url)
|
41
|
+
perform(request)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'net/https'
|
4
|
+
|
5
|
+
module ADN
|
6
|
+
API_HOST = "alpha-api.app.net"
|
7
|
+
API_ENDPOINT = "/stream/0"
|
8
|
+
API_ENDPOINT_POSTS = "#{API_ENDPOINT}/posts"
|
9
|
+
API_ENDPOINT_USERS = "#{API_ENDPOINT}/users"
|
10
|
+
API_ENDPOINT_TOKEN = "#{API_ENDPOINT}/token"
|
11
|
+
HTTP = Net::HTTP.new(API_HOST, 443)
|
12
|
+
|
13
|
+
HTTP.use_ssl = true
|
14
|
+
end
|
data/lib/adn/post.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module ADN
|
4
|
+
class Post
|
5
|
+
attr_accessor :post_id, :created_at, :entities,
|
6
|
+
:html, :id, :num_replies, :reply_to,
|
7
|
+
:source, :text, :thread_id, :user
|
8
|
+
|
9
|
+
def self.send_post(params)
|
10
|
+
result = ADN::API::Post.create(params)
|
11
|
+
Post.new(result["data"]) unless result.has_error?
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(raw_post)
|
15
|
+
if raw_post.respond_to?(:each_pair)
|
16
|
+
set_values(raw_post)
|
17
|
+
post_id = id
|
18
|
+
else
|
19
|
+
post_id = raw_post
|
20
|
+
post_details = details
|
21
|
+
if post_details.has_key? "data"
|
22
|
+
set_values(post_details["data"])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def details
|
28
|
+
if id
|
29
|
+
Hash[self.instance_variables.map { |i| [i.to_s.slice(1..-1), self.instance_variable_get(i)]}]
|
30
|
+
else
|
31
|
+
ADN::API::Post.by_id(post_id)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def created_at
|
36
|
+
DateTime.parse(@created_at)
|
37
|
+
end
|
38
|
+
|
39
|
+
def user
|
40
|
+
ADN::User.new(@user)
|
41
|
+
end
|
42
|
+
|
43
|
+
def reply_to_post
|
44
|
+
result = ADN::API::Post.by_id(reply_to)
|
45
|
+
ADN.create_instance(result["data"], Post) unless result.has_error?
|
46
|
+
end
|
47
|
+
|
48
|
+
def replies(params = nil)
|
49
|
+
result = ADN::API::Post.replies(id, params)
|
50
|
+
ADN.create_collection(result["data"], Post) unless result.has_error?
|
51
|
+
end
|
52
|
+
|
53
|
+
def delete
|
54
|
+
result = ADN::API::Post.delete(id)
|
55
|
+
ADN.create_instance(result["data"], Post) unless result.has_error?
|
56
|
+
end
|
57
|
+
|
58
|
+
def set_values(values)
|
59
|
+
values.each_pair { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/adn/user.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module ADN
|
4
|
+
class User
|
5
|
+
attr_accessor :user_id
|
6
|
+
attr_accessor :avatar_image, :counts, :cover_image,
|
7
|
+
:created_at, :description, :follows_you,
|
8
|
+
:id, :is_follower, :is_following, :is_muted,
|
9
|
+
:locale, :name, :timezone, :type, :username,
|
10
|
+
:you_follow, :you_muted
|
11
|
+
|
12
|
+
def initialize(user)
|
13
|
+
if user.respond_to?(:each_pair)
|
14
|
+
set_values(user)
|
15
|
+
self.user_id = id
|
16
|
+
else
|
17
|
+
self.user_id = user
|
18
|
+
user_details = details
|
19
|
+
if details.has_key? "data"
|
20
|
+
set_values(user_details["data"])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def details
|
26
|
+
if id
|
27
|
+
Hash[self.instance_variables.map { |i| [i.to_s.slice(1..-1), self.instance_variable_get(i)]}]
|
28
|
+
else
|
29
|
+
ADN::API::User.retrieve(user_id)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def created_at
|
34
|
+
DateTime.parse(@created_at)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Followers/Users
|
38
|
+
|
39
|
+
def get_user(user)
|
40
|
+
user.is_a?(ADN::User) ? user.id : user
|
41
|
+
end
|
42
|
+
|
43
|
+
def follow(user)
|
44
|
+
user_id = get_user(user)
|
45
|
+
result = ADN.post("/stream/0/users/#{user_id}/follow")
|
46
|
+
ADN.create_instance(result["data"], User) unless result.has_error?
|
47
|
+
end
|
48
|
+
|
49
|
+
def unfollow(user)
|
50
|
+
user_id = get_user(user)
|
51
|
+
result = ADN.delete("/stream/0/users/#{user_id}/follow")
|
52
|
+
ADN.create_instance(result["data"], User) unless result.has_error?
|
53
|
+
end
|
54
|
+
|
55
|
+
def followers
|
56
|
+
result = ADN::API::User.followers(user_id)
|
57
|
+
ADN.create_collection(result["data"], User) unless result.has_error?
|
58
|
+
end
|
59
|
+
|
60
|
+
def following
|
61
|
+
result = ADN::API::User.following(user_id)
|
62
|
+
ADN.create_collection(result["data"], User) unless result.has_error?
|
63
|
+
end
|
64
|
+
|
65
|
+
# Mute
|
66
|
+
|
67
|
+
def mute(user)
|
68
|
+
user_id = get_user(user)
|
69
|
+
result = ADN.post("#{ADN::API_ENDPOINT_USERS}/#{user_id}/mute")
|
70
|
+
ADN.create_instance(result["data"], User) unless result.has_error?
|
71
|
+
end
|
72
|
+
|
73
|
+
def unmute(user)
|
74
|
+
user_id = get_user(user)
|
75
|
+
result = ADN.delete("#{ADN::API_ENDPOINT_USERS}/#{user_id}/mute")
|
76
|
+
ADN.create_instance(result["data"], User) unless result.has_error?
|
77
|
+
end
|
78
|
+
|
79
|
+
def mute_list
|
80
|
+
result = ADN.get("#{ADN::API_ENDPOINT_USERS}/me/muted")
|
81
|
+
ADN.create_collection(result["data"], User) unless result.has_error?
|
82
|
+
end
|
83
|
+
|
84
|
+
# Posts
|
85
|
+
|
86
|
+
def posts(params = nil)
|
87
|
+
result = ADN::API::Post.by_user(user_id, params)
|
88
|
+
ADN.create_collection(result["data"], Post) unless result.has_error?
|
89
|
+
end
|
90
|
+
|
91
|
+
def stream(params = nil)
|
92
|
+
result = ADN::API::Post.stream(params)
|
93
|
+
ADN.create_collection(result["data"], Post) unless result.has_error?
|
94
|
+
end
|
95
|
+
|
96
|
+
def mentions(params = nil)
|
97
|
+
result = ADN::API::Post.mentioning_user(user_id, params)
|
98
|
+
ADN.create_collection(result["data"], Post) unless result.has_error?
|
99
|
+
end
|
100
|
+
|
101
|
+
def set_values(values)
|
102
|
+
values.each_pair { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
|
103
|
+
end
|
104
|
+
|
105
|
+
def has_error?
|
106
|
+
self.id.nil?
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/lib/adn/version.rb
CHANGED
data/lib/adn.rb
CHANGED
@@ -1,5 +1,54 @@
|
|
1
|
-
require "adn/version"
|
2
1
|
|
3
|
-
|
4
|
-
|
2
|
+
#
|
3
|
+
# ADN - A simple and easy to use App.net Ruby library
|
4
|
+
#
|
5
|
+
# Copyright (c) 2012 Kishyr Ramdial
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
# a copy of this software and associated documentation files (the
|
9
|
+
# "Software"), to deal in the Software without restriction, including
|
10
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
13
|
+
# the following conditions:
|
14
|
+
#
|
15
|
+
# The above copyright notice and this permission notice shall be
|
16
|
+
# included in all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
|
26
|
+
require 'uri'
|
27
|
+
require 'json'
|
28
|
+
require 'date'
|
29
|
+
|
30
|
+
%w{constants api post user version}.each { |f| require_relative "adn/#{f}" }
|
31
|
+
|
32
|
+
module ADN
|
33
|
+
class Error < StandardError; end
|
34
|
+
|
35
|
+
def self.token=(token)
|
36
|
+
@token = token
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.token
|
40
|
+
@token
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.has_error?(hash)
|
44
|
+
hash.has_key?("error")
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.create_instance(data, type)
|
48
|
+
type.new(data)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.create_collection(data, type)
|
52
|
+
data.collect { |t| type.new(t) }
|
53
|
+
end
|
5
54
|
end
|