gooru 0.0.2

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,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rbenv*
19
+ .env
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gooru.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Passion Dragon
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.
@@ -0,0 +1,96 @@
1
+ # Gooru
2
+
3
+ The gooru gem allows your Ruby app to talk to the [Gooru API](http://developers.goorulearning.org)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gooru'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gooru
18
+
19
+ ## Setup
20
+
21
+ ### Gooru API key
22
+
23
+ Some areas of the Gooru API require sign in via an API key.
24
+
25
+ You may want to [request an API key](http://developers.goorulearning.org/request-a-key) from Gooru before you get started.
26
+
27
+ ### Environment variables
28
+
29
+ If you're using an API key, you may want to store it in an environment variable.
30
+
31
+ Environment variables can be a way to store sensitive data you don't want in source control.
32
+
33
+ Consider using a tool like [Dotenv](https://github.com/bkeepers/dotenv) to manage these variables across different developer and server environments.
34
+
35
+ You'll see the environment variable approach used in the examples below.
36
+
37
+ ## Usage
38
+
39
+ ### Sign In
40
+
41
+ The Sign In call takes your API key and returns a session token.
42
+
43
+ If you're using the signed in areas of the Gooru API, you'll need to hang on to the returned session token and use it in later requests.
44
+
45
+ The Sign In call is not needed if you're only using the public areas of the API.
46
+
47
+ response = Gooru::SignIn.post(
48
+ apiKey: ENV["GOORU_API_KEY"],
49
+ userName: ENV["GOORU_USER_NAME"],
50
+ password: ENV["GOORU_PASSWORD"])
51
+
52
+ if response.success?
53
+ puts "You've been authenticated!"
54
+ puts "Your session token is #{response.data['token']}"
55
+ else
56
+ puts "You were unable to be authenticated…"
57
+ puts "The error message was: #{response.data['error']}"
58
+ end
59
+
60
+ *Required parameters*
61
+
62
+ * `apiKey`
63
+ * `userName`
64
+ * `password`
65
+
66
+ ### Resources
67
+
68
+ The Resources call takes a query and returns a list of matching resources.
69
+
70
+ You can optionally pass a session token if you're signed in, but it is not required.
71
+
72
+ response = Gooru::Resources.get(
73
+ query: "algebra")
74
+
75
+ if response.success?
76
+ results = response.data["searchResults"]
77
+ puts "We found #{results.length} resources matching 'algebra'"
78
+ else
79
+ puts "The error message was: #{response.data['error']}"
80
+ end
81
+
82
+ *Required parameters*
83
+
84
+ * `query`
85
+
86
+ *Optional parameters*
87
+
88
+ * `sessionToken`
89
+
90
+ ## Contributing
91
+
92
+ 1. Fork it
93
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
94
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
95
+ 4. Push to the branch (`git push origin my-new-feature`)
96
+ 5. Create new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << ["lib", "test"]
6
+ t.pattern = "test/**/*_test.rb"
7
+ t.verbose = true
8
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gooru/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "gooru"
8
+ gem.version = Gooru::VERSION
9
+ gem.authors = ["Brandon Beacher"]
10
+ gem.email = ["brandon.beacher@gmail.com"]
11
+ gem.description = %q{}
12
+ gem.summary = %q{The gooru gem allows your Ruby app to talk to the Gooru API}
13
+ gem.homepage = "https://github.com/highgroove/gooru"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "weary"
21
+
22
+ gem.add_development_dependency "dotenv"
23
+ gem.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,14 @@
1
+ require "stringio"
2
+ require "weary"
3
+
4
+ require "gooru/client"
5
+ require "gooru/client/resources"
6
+ require "gooru/client/sign_in"
7
+ require "gooru/request"
8
+ require "gooru/resources"
9
+ require "gooru/response"
10
+ require "gooru/sign_in"
11
+ require "gooru/version"
12
+
13
+ module Gooru
14
+ end
@@ -0,0 +1,4 @@
1
+ module Gooru
2
+ class Client < Weary::Client
3
+ end
4
+ end
@@ -0,0 +1,18 @@
1
+ module Gooru
2
+ class Client
3
+ class Resources < Gooru::Client
4
+ domain ENV["GOORU_URL"]
5
+
6
+ get :get, "gooru-search/rest/search/resource.json" do |resource|
7
+ resource.required \
8
+ :query
9
+
10
+ resource.optional \
11
+ :pageNum,
12
+ :pageSize,
13
+ :sessionToken
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module Gooru
2
+ class Client
3
+ class SignIn < Gooru::Client
4
+ domain ENV["GOORU_URL"]
5
+
6
+ post :post, "gooruapi/rest/account/signin.json" do |resource|
7
+ resource.required \
8
+ :apiKey,
9
+ :password,
10
+ :userName
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ module Gooru
2
+ class Request
3
+
4
+ def self.get(options = {})
5
+ response = client.new.get(options).perform
6
+ Gooru::Response.new(response)
7
+ end
8
+
9
+ def self.post(options = {})
10
+ response = client.new.post(options).perform
11
+ Gooru::Response.new(response)
12
+ end
13
+
14
+ private
15
+
16
+ def self.client
17
+ raise NotImplementedError
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ module Gooru
2
+ class Resources < Gooru::Request
3
+
4
+ private
5
+
6
+ def self.client
7
+ Gooru::Client::Resources
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,49 @@
1
+ module Gooru
2
+ class Response
3
+ attr_reader :data
4
+ attr_reader :status
5
+
6
+ def initialize(weary_response)
7
+ @data = parse(weary_response.body)
8
+ @status = weary_response.status
9
+ end
10
+
11
+ def error?
12
+ has_error_key? ||
13
+ internal_server_error?
14
+ end
15
+
16
+ def error_message
17
+ if has_error_key?
18
+ data["error"]
19
+ elsif internal_server_error?
20
+ data["status"]
21
+ else
22
+ ""
23
+ end
24
+ end
25
+
26
+ def success?
27
+ !error?
28
+ end
29
+
30
+ private
31
+
32
+ def has_error_key?
33
+ data.has_key?("error")
34
+ end
35
+
36
+ def internal_server_error?
37
+ status == 500
38
+ end
39
+
40
+ def parse(body)
41
+ if body.match(/^error:(.*)/)
42
+ { "error" => Regexp.last_match[1] }
43
+ else
44
+ MultiJson.decode(body)
45
+ end
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,11 @@
1
+ module Gooru
2
+ class SignIn < Gooru::Request
3
+
4
+ private
5
+
6
+ def self.client
7
+ Gooru::Client::SignIn
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Gooru
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,20 @@
1
+ require "test_helper"
2
+
3
+ class ResourcesTest < MiniTest::Unit::TestCase
4
+
5
+ def test_get
6
+ response = Gooru::Resources.get(
7
+ query: "all")
8
+
9
+ assert(response.data.has_key?("searchResults"))
10
+ end
11
+
12
+ def test_get_with_pagination
13
+ response = Gooru::Resources.get(
14
+ query: "all",
15
+ pageNum: 2,
16
+ pageSize: 5)
17
+
18
+ assert(response.data["searchResults"].count == 5)
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ require "test_helper"
2
+
3
+ class SignInTest < MiniTest::Unit::TestCase
4
+
5
+ def test_post
6
+ response = Gooru::SignIn.post(
7
+ apiKey: ENV["GOORU_API_KEY"],
8
+ userName: ENV["GOORU_USER_NAME"],
9
+ password: ENV["GOORU_PASSWORD"])
10
+
11
+ assert(response.data.has_key?("token"))
12
+ end
13
+
14
+ def test_unsuccessful_post
15
+ response = Gooru::SignIn.post(
16
+ apiKey: "invalid-api-key",
17
+ userName: "invalid-username",
18
+ password: "invalid-password")
19
+
20
+ assert(response.data.has_key?("error"))
21
+ end
22
+
23
+ end
@@ -0,0 +1,6 @@
1
+ require "dotenv"
2
+ Dotenv.load
3
+
4
+ require "gooru"
5
+ require "minitest/autorun"
6
+
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gooru
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brandon Beacher
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: weary
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: dotenv
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ''
63
+ email:
64
+ - brandon.beacher@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - gooru.gemspec
75
+ - lib/gooru.rb
76
+ - lib/gooru/client.rb
77
+ - lib/gooru/client/resources.rb
78
+ - lib/gooru/client/sign_in.rb
79
+ - lib/gooru/request.rb
80
+ - lib/gooru/resources.rb
81
+ - lib/gooru/response.rb
82
+ - lib/gooru/sign_in.rb
83
+ - lib/gooru/version.rb
84
+ - test/resources_test.rb
85
+ - test/sign_in_test.rb
86
+ - test/test_helper.rb
87
+ homepage: https://github.com/highgroove/gooru
88
+ licenses: []
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.23
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: The gooru gem allows your Ruby app to talk to the Gooru API
111
+ test_files:
112
+ - test/resources_test.rb
113
+ - test/sign_in_test.rb
114
+ - test/test_helper.rb