edools 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 20609e1a272f49367e964e284270970df35e128c
4
+ data.tar.gz: c597876cc0ae09e472ef499897b22472780efc6c
5
+ SHA512:
6
+ metadata.gz: bc3927565bf35d551fc254a07a3e439e304b722006f1c3763a3df93356ff46e2ebe9639a1f8a757bec82d79857d3b2d1966dc2b787103d4bce975cd862f4a199
7
+ data.tar.gz: 548629a992677ce239969b23ad4b9e7847b7c4f0483abfa982cd682e545ce9d969a250a4e672aace98caf6e511d267e5cab14a1d6594dc304044b127c7ec53d5
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.15.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at wertermeira@hotmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in edools.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Werter Meira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,117 @@
1
+ # Edools
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/edools`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'edools'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install edools
21
+
22
+ ## Usage
23
+ ### config
24
+ ```
25
+ config = {
26
+ :access_token => 'token'
27
+ }
28
+ client = Edools::Client.new(config)
29
+ ```
30
+
31
+ ### school
32
+ http://docs.edools.com/api/V1/SchoolsController.html <br />
33
+ use token for create school wizard
34
+ ```
35
+ params = {"school": {"name": "test name", "email": "test@gtest.com", "password": "1234567" }}
36
+ client.create_school(params)
37
+ ```
38
+
39
+
40
+ #### courses resource
41
+ http://docs.edools.com/api/V1/CoursesController.html <br />
42
+ use generated token for school
43
+ ```
44
+ #list
45
+ client.courses
46
+
47
+ #create
48
+ params = {school_cource: {name: "course test}}
49
+ client.create_course(params)
50
+
51
+ #update
52
+ id = 10
53
+ params = {"school_cource": {"name": "course test"}}
54
+ client.update_course(id, params)
55
+
56
+ #show
57
+ id = 10
58
+ client.show_course(id)
59
+
60
+ #destroy
61
+ client.destroy_course(id)
62
+ ```
63
+ #### school_products resource
64
+ http://docs.edools.com/api/V1/SchoolProductsController.html not complet <br />
65
+ use generated token for school
66
+ ```
67
+ #list
68
+ client.products
69
+
70
+ #create
71
+ params = {school_product: {"name": "product test, "school_id": 10}}
72
+ client.create_product(params)
73
+ ```
74
+
75
+ #### studantes resource
76
+
77
+ http://docs.edools.com/api/V1/InvitationsController.html<br />
78
+ http://docs.edools.com/api/V1/UsersController.html<br />
79
+ use generated token for school
80
+ ```
81
+ #list
82
+ client.studantes
83
+
84
+ #create with invidation
85
+ params = {invitation: {"first_name": "First", "last_name": "Last", "email": "first@gmail.com", "password": "12345678", "password_confirmation": "12345678" }}
86
+ client.create_and_invitation_studant(params)
87
+
88
+ #create without invidation
89
+ params = {studant: {"first_name": "First", "last_name": "Last", "email": "first@gmail.com", "password": "12345678", "password_confirmation": "12345678" }}
90
+ client.create_studant(params)
91
+
92
+ #update
93
+ id = 10
94
+ params = {studant: {"first_name": "First", "last_name": "Last" }}
95
+
96
+ client.update_studant(id, params)
97
+
98
+ #show
99
+ id = 10
100
+ client.show_studant(id)
101
+
102
+ #destroy
103
+ client.destroy_studant(id)
104
+ ```
105
+
106
+
107
+ ## Contributing
108
+
109
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wertermeira/edools. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
110
+
111
+ ## License
112
+
113
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
114
+
115
+ ## Code of Conduct
116
+
117
+ Everyone interacting in the Edools project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/edools/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "edools"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
Binary file
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "edools/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "edools"
8
+ spec.version = Edools::VERSION
9
+ spec.authors = ["Werter Meira"]
10
+ spec.email = ["wertermeira@hotmail.com"]
11
+
12
+ spec.summary = "Manage api Edools"
13
+ spec.description = "Site: https://www.edools.com/"
14
+ spec.homepage = "https://github.com/wertermeira/edools"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+ spec.add_dependency 'excon', '~> 0.37'
33
+ spec.add_development_dependency "bundler", "~> 1.15"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ end
@@ -0,0 +1,169 @@
1
+ require "edools/version"
2
+ require 'excon'
3
+ require 'json'
4
+
5
+ require File.dirname(__FILE__) + '/edools/utils'
6
+ require File.dirname(__FILE__) + '/edools/exceptions'
7
+
8
+ module Edools
9
+ class Client
10
+
11
+ BASE_URI = "https://core.myedools.info/api".freeze
12
+
13
+ attr_accessor :access_token
14
+
15
+ def initialize(config = {})
16
+ @access_token = config[:access_token]
17
+ @raise_errors = config[:raise_errors] || false
18
+ @retries = config[:retries] || 0
19
+ @read_timeout = config[:read_timeout] || 10
20
+ @write_timeout = config[:write_timeout] || 10
21
+ @connection = Excon.new(BASE_URI, persistent: config[:persistent] || false)
22
+ end
23
+
24
+ def inspect
25
+ vars = instance_variables.map { |v| "#{v}=#{instance_variable_get(v).inspect}" }.join(', ')
26
+ "<#{self.class}: #{vars}>"
27
+ end
28
+
29
+ def close_connection
30
+ @connection.reset
31
+ end
32
+ #schools
33
+
34
+ #show school
35
+ def show_school(id)
36
+ run(:get, "/schools/#{id}", [200])
37
+ end
38
+ #create school
39
+ def create_school(params = {})
40
+ run(:post, "/schools/wizard", [201,422], JSON.dump(params))
41
+ end
42
+ #update school
43
+ def update_school(id, params = {})
44
+ run(:put, "/schools/#{id}", [200,422], JSON.dump(params))
45
+ end
46
+
47
+ #courses
48
+ #list courses
49
+ def courses
50
+ run(:get,"/courses", [200])
51
+ end
52
+ #show course
53
+ def show_course(id)
54
+ run(:get, "/courses/#{id}", [200])
55
+ end
56
+ #create course
57
+ def create_course(params = {})
58
+ run(:post, "/courses", [201,422], JSON.dump(params))
59
+ end
60
+
61
+ #update course
62
+ def update_course(id, params = {})
63
+ run(:put, "/courses/#{id}", [200,422], JSON.dump(params))
64
+ end
65
+
66
+ #destroy course
67
+ def destroy_course(id)
68
+ run(:put, "/courses/#{id}", [204,404])
69
+ end
70
+ #products
71
+ #TODO error not rerturn products
72
+ #list products
73
+ def products
74
+ run(:get,"/school_products", [200])
75
+ end
76
+
77
+ #create products
78
+ def create_product(school_id, params = {})
79
+ run(:post, "/schools/#{school_id}/school_products", [201,422], JSON.dump(params))
80
+ end
81
+
82
+ #studantes
83
+ #studants
84
+ def studants
85
+ run(:get,"/studants", [200])
86
+ end
87
+
88
+ #create studants and invitation
89
+ def create_and_invitation_studant(params = {})
90
+ run(:post, "/invitations", [201,422], JSON.dump(params))
91
+ end
92
+ #show studant
93
+ def show_studant(id)
94
+ run(:get, "/studants/#{id}", [200,404])
95
+ end
96
+
97
+ #create studants
98
+ def create_studant(params = {})
99
+ run(:post, "/studants/", [201,422], JSON.dump(params))
100
+ end
101
+
102
+
103
+ #update studants
104
+ def update_studant(id, params = {})
105
+ run(:put, "/studants/#{id}", [200,422], JSON.dump(params))
106
+ end
107
+
108
+ #destroy studant
109
+ def destroy_studant(id)
110
+ run(:delete, "/studants/#{id}", [204,404])
111
+ end
112
+
113
+
114
+ protected
115
+
116
+ def run(verb, path, expected_status_codes, params = {}, idempotent = true)
117
+ run!(verb, path, expected_status_codes, params, idempotent)
118
+ rescue Error => e
119
+ if @raise_errors
120
+ raise e
121
+ else
122
+ false
123
+ end
124
+ end
125
+
126
+
127
+ def run!(verb, path, expected_status_codes, params_or_body = nil, idempotent = true)
128
+ packet = {
129
+ idempotent: idempotent,
130
+ expects: expected_status_codes,
131
+ method: verb,
132
+ path: path,
133
+ read_timeout: @read_timeout,
134
+ write_timeout: @write_timeout,
135
+ retry_limit: @retries,
136
+ headers: {
137
+ 'Content-Type' => 'application/json',
138
+ 'Accept' => 'application/vnd.edools.core.v1+json'
139
+ }
140
+ }
141
+ if params_or_body.is_a?(Hash)
142
+ packet.merge!(query: params_or_body)
143
+ else
144
+ packet.merge!(body: params_or_body)
145
+ end
146
+
147
+ if !@access_token.nil? && @access_token != ''
148
+ packet[:headers].merge!('Authorization' => 'Token token="' + @access_token +'"')
149
+ end
150
+
151
+ response = @connection.request(packet)
152
+ @response_body = response.body
153
+ ::JSON.load(@response_body)
154
+
155
+ rescue Excon::Errors::NotFound => exception
156
+ raise(ResourceNotFound, "Error: #{exception.message}")
157
+ rescue Excon::Errors::BadRequest => exception
158
+ raise(BadRequest, "Error: #{exception.message}")
159
+ rescue Excon::Errors::Forbidden => exception
160
+ raise(InsufficientClientScopeError, "Error: #{exception.message}")
161
+ rescue Excon::Errors::Unauthorized => exception
162
+ raise(AuthenticationError, "Error: #{exception.message}")
163
+ rescue Excon::Errors::Error => exception
164
+ raise(HTTPError, "Error: #{exception.message}")
165
+ end
166
+
167
+
168
+ end
169
+ end
@@ -0,0 +1,9 @@
1
+ module Edools
2
+ class ImplementationError < StandardError; end
3
+ class Error < StandardError; end
4
+ class AuthenticationError < Error; end
5
+ class HTTPError < Error; end
6
+ class InsufficientClientScopeError < Error; end
7
+ class BadRequest < Error; end
8
+ class ResourceNotFound < Error; end
9
+ end
@@ -0,0 +1,11 @@
1
+ class Array
2
+ def self.wrap(object)
3
+ if object.nil?
4
+ []
5
+ elsif object.respond_to?(:to_ary)
6
+ object.to_ary || [object]
7
+ else
8
+ [object]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Edools
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: edools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Werter Meira
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: excon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.37'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.37'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: 'Site: https://www.edools.com/'
70
+ email:
71
+ - wertermeira@hotmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - edools-0.1.0.gem
87
+ - edools.gemspec
88
+ - lib/edools.rb
89
+ - lib/edools/exceptions.rb
90
+ - lib/edools/utils.rb
91
+ - lib/edools/version.rb
92
+ homepage: https://github.com/wertermeira/edools
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ allowed_push_host: https://rubygems.org
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.6.8
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Manage api Edools
117
+ test_files: []