edools-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +116 -0
- data/LICENSE.txt +20 -0
- data/README.md +19 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/edools.rb +5 -0
- data/lib/edools/config.rb +32 -0
- data/lib/edools/core.rb +7 -0
- data/lib/edools/core/base.rb +17 -0
- data/lib/edools/core/enrollment.rb +10 -0
- data/lib/edools/core/organization.rb +10 -0
- data/lib/edools/core/paginated_collection.rb +30 -0
- data/lib/edools/core/registration.rb +10 -0
- data/lib/edools/core/school.rb +10 -0
- data/lib/edools/core/school_product.rb +10 -0
- data/lib/edools/core/student.rb +18 -0
- data/lib/edools/initialization.rb +9 -0
- data/spec/edools/core/base_spec.rb +9 -0
- data/spec/edools/core/enrollment_spec.rb +33 -0
- data/spec/edools/core/organization_spec.rb +33 -0
- data/spec/edools/core/registration_spec.rb +33 -0
- data/spec/edools/core/school_product_spec.rb +33 -0
- data/spec/edools/core/school_spec.rb +33 -0
- data/spec/edools/core/student_spec.rb +32 -0
- data/spec/fixtures/vcr_cassettes/Edools_Core_Student/create_the_student.yml +65 -0
- data/spec/fixtures/vcr_cassettes/Edools_Core_Student/destroy_the_student.yml +113 -0
- data/spec/fixtures/vcr_cassettes/Edools_Core_Student/finds_all_student.yml +63 -0
- data/spec/fixtures/vcr_cassettes/Edools_Core_Student/finds_the_student.yml +61 -0
- data/spec/fixtures/vcr_cassettes/Edools_Core_Student/update_the_student.yml +173 -0
- data/spec/spec_helper.rb +40 -0
- metadata +218 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d3eade3c23eee728077692f503d70ba857c08046
|
4
|
+
data.tar.gz: 5091623e13c4f66a376c337444a29e92ff01798f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 554440efb0345b30a1374dc8df8e6f4ec24b292d2dfd8c5c6fff7fec4a62531c8377da9162a10d458919f1858b401d408fe3a6d7109718ed735882c548881ccf
|
7
|
+
data.tar.gz: d9d1bdf18515517ba422e2fa5c54481525bb92299d7207a4366623af9ea22c75fedb784ba9f7a7e284f0fa1b818c61166ca120422b60d9845526def719b84b70
|
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'activeresource', '>= 4.0.0'
|
4
|
+
# gem 'kaminari', '>= 0.16.0'
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem 'rspec', "~> 3.0.0"
|
10
|
+
gem 'vcr', "~> 2.9.2"
|
11
|
+
gem 'webmock', "~> 1.18.0"
|
12
|
+
gem 'pry', "~> 0.10.0"
|
13
|
+
gem "yard", "~> 0.7"
|
14
|
+
gem "rdoc", "~> 3.12"
|
15
|
+
gem "bundler", "~> 1.0"
|
16
|
+
gem "jeweler", "~> 2.0.1"
|
17
|
+
gem "simplecov", ">= 0"
|
18
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (4.1.4)
|
5
|
+
activesupport (= 4.1.4)
|
6
|
+
builder (~> 3.1)
|
7
|
+
activeresource (4.0.0)
|
8
|
+
activemodel (~> 4.0)
|
9
|
+
activesupport (~> 4.0)
|
10
|
+
rails-observers (~> 0.1.1)
|
11
|
+
activesupport (4.1.4)
|
12
|
+
i18n (~> 0.6, >= 0.6.9)
|
13
|
+
json (~> 1.7, >= 1.7.7)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
thread_safe (~> 0.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
addressable (2.3.6)
|
18
|
+
builder (3.2.2)
|
19
|
+
coderay (1.1.0)
|
20
|
+
crack (0.4.2)
|
21
|
+
safe_yaml (~> 1.0.0)
|
22
|
+
descendants_tracker (0.0.4)
|
23
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
24
|
+
diff-lcs (1.2.5)
|
25
|
+
docile (1.1.5)
|
26
|
+
faraday (0.9.0)
|
27
|
+
multipart-post (>= 1.2, < 3)
|
28
|
+
git (1.2.7)
|
29
|
+
github_api (0.11.3)
|
30
|
+
addressable (~> 2.3)
|
31
|
+
descendants_tracker (~> 0.0.1)
|
32
|
+
faraday (~> 0.8, < 0.10)
|
33
|
+
hashie (>= 1.2)
|
34
|
+
multi_json (>= 1.7.5, < 2.0)
|
35
|
+
nokogiri (~> 1.6.0)
|
36
|
+
oauth2
|
37
|
+
hashie (3.2.0)
|
38
|
+
highline (1.6.21)
|
39
|
+
i18n (0.6.11)
|
40
|
+
jeweler (2.0.1)
|
41
|
+
builder
|
42
|
+
bundler (>= 1.0)
|
43
|
+
git (>= 1.2.5)
|
44
|
+
github_api
|
45
|
+
highline (>= 1.6.15)
|
46
|
+
nokogiri (>= 1.5.10)
|
47
|
+
rake
|
48
|
+
rdoc
|
49
|
+
json (1.8.1)
|
50
|
+
jwt (1.0.0)
|
51
|
+
method_source (0.8.2)
|
52
|
+
mini_portile (0.6.0)
|
53
|
+
minitest (5.4.0)
|
54
|
+
multi_json (1.10.1)
|
55
|
+
multi_xml (0.5.5)
|
56
|
+
multipart-post (2.0.0)
|
57
|
+
nokogiri (1.6.3.1)
|
58
|
+
mini_portile (= 0.6.0)
|
59
|
+
oauth2 (1.0.0)
|
60
|
+
faraday (>= 0.8, < 0.10)
|
61
|
+
jwt (~> 1.0)
|
62
|
+
multi_json (~> 1.3)
|
63
|
+
multi_xml (~> 0.5)
|
64
|
+
rack (~> 1.2)
|
65
|
+
pry (0.10.0)
|
66
|
+
coderay (~> 1.1.0)
|
67
|
+
method_source (~> 0.8.1)
|
68
|
+
slop (~> 3.4)
|
69
|
+
rack (1.5.2)
|
70
|
+
rails-observers (0.1.2)
|
71
|
+
activemodel (~> 4.0)
|
72
|
+
rake (10.3.2)
|
73
|
+
rdoc (3.12.2)
|
74
|
+
json (~> 1.4)
|
75
|
+
rspec (3.0.0)
|
76
|
+
rspec-core (~> 3.0.0)
|
77
|
+
rspec-expectations (~> 3.0.0)
|
78
|
+
rspec-mocks (~> 3.0.0)
|
79
|
+
rspec-core (3.0.3)
|
80
|
+
rspec-support (~> 3.0.0)
|
81
|
+
rspec-expectations (3.0.3)
|
82
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
83
|
+
rspec-support (~> 3.0.0)
|
84
|
+
rspec-mocks (3.0.3)
|
85
|
+
rspec-support (~> 3.0.0)
|
86
|
+
rspec-support (3.0.3)
|
87
|
+
safe_yaml (1.0.3)
|
88
|
+
simplecov (0.9.0)
|
89
|
+
docile (~> 1.1.0)
|
90
|
+
multi_json
|
91
|
+
simplecov-html (~> 0.8.0)
|
92
|
+
simplecov-html (0.8.0)
|
93
|
+
slop (3.6.0)
|
94
|
+
thread_safe (0.3.4)
|
95
|
+
tzinfo (1.2.1)
|
96
|
+
thread_safe (~> 0.1)
|
97
|
+
vcr (2.9.2)
|
98
|
+
webmock (1.18.0)
|
99
|
+
addressable (>= 2.3.6)
|
100
|
+
crack (>= 0.3.2)
|
101
|
+
yard (0.8.7.4)
|
102
|
+
|
103
|
+
PLATFORMS
|
104
|
+
ruby
|
105
|
+
|
106
|
+
DEPENDENCIES
|
107
|
+
activeresource (>= 4.0.0)
|
108
|
+
bundler (~> 1.0)
|
109
|
+
jeweler (~> 2.0.1)
|
110
|
+
pry (~> 0.10.0)
|
111
|
+
rdoc (~> 3.12)
|
112
|
+
rspec (~> 3.0.0)
|
113
|
+
simplecov
|
114
|
+
vcr (~> 2.9.2)
|
115
|
+
webmock (~> 1.18.0)
|
116
|
+
yard (~> 0.7)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Vinicius Kastrup
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= edools-api
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to edools-api
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2014 Vinicius Kastrup. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "edools-api"
|
18
|
+
gem.homepage = "http://github.com/Edools/edools-api"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{This gem is a Ruby wrapper for all Edools API's}
|
21
|
+
gem.description = %Q{
|
22
|
+
With this gem you'll be able to access and manipulate all the data of your School or Organization
|
23
|
+
hosted at Edools.
|
24
|
+
}
|
25
|
+
gem.email = "viniciusmkm@gmail.com"
|
26
|
+
gem.authors = ["Vinicius Kastrup"]
|
27
|
+
# dependencies defined in Gemfile
|
28
|
+
end
|
29
|
+
Jeweler::RubygemsDotOrgTasks.new
|
30
|
+
require 'rspec/core'
|
31
|
+
require 'rspec/core/rake_task'
|
32
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
33
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Code coverage detail"
|
37
|
+
task :simplecov do
|
38
|
+
ENV['COVERAGE'] = "true"
|
39
|
+
Rake::Task['test'].execute
|
40
|
+
end
|
41
|
+
|
42
|
+
task :default => :spec
|
43
|
+
|
44
|
+
require 'yard'
|
45
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/edools.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'edools/initialization'
|
2
|
+
|
3
|
+
module Edools
|
4
|
+
class << self
|
5
|
+
attr_accessor :credentials, :format
|
6
|
+
|
7
|
+
# Set your API credentials using this method.
|
8
|
+
def credentials= (new_credentials)
|
9
|
+
@credentials = new_credentials
|
10
|
+
refresh_config_for_api_objects!
|
11
|
+
@credentials
|
12
|
+
end
|
13
|
+
|
14
|
+
# Set the format that the API uses to either 'json' or 'xml'.
|
15
|
+
# Accepts either a String or a Symbol.
|
16
|
+
def format=(new_format)
|
17
|
+
valid_formats = [:json, :xml]
|
18
|
+
raise ArgumentError, "Invalid format. Supported formats: #{valid_formats.join(', ')}." unless valid_formats.include?(new_format.to_sym)
|
19
|
+
@format = new_format
|
20
|
+
refresh_config_for_api_objects!
|
21
|
+
@format
|
22
|
+
end
|
23
|
+
|
24
|
+
def api_objects
|
25
|
+
ObjectSpace.each_object(Class).select{ |klass| klass < Edools::Core::Base } << Edools::Core::Base
|
26
|
+
end
|
27
|
+
|
28
|
+
def refresh_config_for_api_objects!
|
29
|
+
api_objects.each {|d| d.refresh_config!}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/edools/core.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Edools
|
2
|
+
module Core
|
3
|
+
class Base < ActiveResource::Base
|
4
|
+
self.site = Edools::CORE_BASE_URL
|
5
|
+
self.include_root_in_json = true
|
6
|
+
|
7
|
+
def self.refresh_config!
|
8
|
+
self.format = ActiveResource::Formats::JsonFormat if Edools.format == :json
|
9
|
+
self.format = ActiveResource::Formats::XmlFormat if Edools.format == :xml
|
10
|
+
self.headers['Authorization'] = "Token token=#{Edools.credentials}"
|
11
|
+
self.headers['Accept'] = "application/#{Edools::CORE_VERSION}+#{Edools.format}"
|
12
|
+
end
|
13
|
+
refresh_config!
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'active_resource'
|
2
|
+
|
3
|
+
module Edools
|
4
|
+
module Core
|
5
|
+
class PaginatedCollection < ActiveResource::Collection
|
6
|
+
|
7
|
+
# Our custom array to handle pagination methods
|
8
|
+
attr_accessor :total_pages, :per_page, :total_count, :current_page
|
9
|
+
|
10
|
+
# The initialize method will receive the ActiveResource parsed result
|
11
|
+
# and set @elements.
|
12
|
+
def initialize(parsed = {})
|
13
|
+
@elements = parsed[resource_key(parsed.keys)]
|
14
|
+
@total_pages = parsed["total_pages"]
|
15
|
+
@per_page = parsed["per_page"]
|
16
|
+
@total_count = parsed["total_count"]
|
17
|
+
@current_page = parsed["current_page"]
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def resource_key(keys)
|
23
|
+
(ObjectSpace.each_object(Class)
|
24
|
+
.select{ |klass| klass < Edools::Core::Base }
|
25
|
+
.collect { |klass| klass.name.split("::").last.downcase.pluralize } & keys).first
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'edools/core/base'
|
2
|
+
require 'edools/core/paginated_collection'
|
3
|
+
|
4
|
+
module Edools
|
5
|
+
module Core
|
6
|
+
class Student < Edools::Core::Base
|
7
|
+
self.collection_parser = PaginatedCollection
|
8
|
+
|
9
|
+
def to_json(options={})
|
10
|
+
super(include_root_in_json ? { root: 'user' }.merge(options) : options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_xml(options={})
|
14
|
+
super({ root: 'user' }.merge(options))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|