rubykhan 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bec0c1ae5ebd2ab2537e2ac37a78fae1a2d870ae
4
- data.tar.gz: 70cd2fd9c6def184c726b1f11a9781249f53bdc6
3
+ metadata.gz: 518cf524ff5f5807da8cb0f146a0ce86471dea84
4
+ data.tar.gz: 407637a0963e13bddf9c125258be95267eca8557
5
5
  SHA512:
6
- metadata.gz: f71cbde9f612a12db1541e76981c5c93f10dfde14560c53726dfbbcf0a498354e9f74d8fb34e9f01809ea8ed9417047d46eda066eeaf62fee6b2ef06179546c2
7
- data.tar.gz: 2105c4b6096180e6a70d55e853a7f6a8dbe2515fb3b6b7465bd1d50bd93645be4c9c41b7eeefd4e7919258b761f2fa8f637132cda85af575184a6188e3e39af5
6
+ metadata.gz: c290d5454784dcb2dcbf03d5761b2c8397c520a3d76a3143908258caccc075f205c8a9f2c0e05051581c7012107cd4d9eb6c5cd20c9b573e8705d220b4f3f6ed
7
+ data.tar.gz: 263dce5d464a64e1a0c9e19d7c0b68577916a7cc9974e0a5e93c718a089d6fef31cc0cb825bb06c47a3ac7d5cd0606b4a579a2f2bf6a461e95e24b9ee0859e9c
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore CHANGED
@@ -1,17 +1,9 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
1
  coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
2
+ coverage.data
13
3
  rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
4
+ doc
5
+ .yardoc
6
+ .bundle
7
+ pkg
8
+ .DS_Store
9
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - jruby-19mode
6
+ - ruby-head
data/Gemfile CHANGED
@@ -1,4 +1,21 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in rubykhan.gemspec
4
- gemspec
3
+ gem 'httparty'
4
+ gem 'rake'
5
+
6
+ group :development do
7
+ gem 'pry'
8
+ gem 'simplecov'
9
+ gem 'jeweler', '~> 1.8.7'
10
+ gem 'bundler', '~> 1.0'
11
+ gem 'rdoc', '~> 3.12'
12
+ gem 'shoulda', '>=0'
13
+ end
14
+
15
+ group :test do
16
+ gem 'webmock'
17
+ gem 'simplecov'
18
+ gem 'coveralls'
19
+ gem 'rspec'
20
+ gem 'shoulda-matchers'
21
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,124 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.1)
5
+ i18n (~> 0.6, >= 0.6.4)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ addressable (2.3.5)
11
+ atomic (1.1.14)
12
+ builder (3.2.2)
13
+ coderay (1.1.0)
14
+ coveralls (0.7.0)
15
+ multi_json (~> 1.3)
16
+ rest-client
17
+ simplecov (>= 0.7)
18
+ term-ansicolor
19
+ thor
20
+ crack (0.4.1)
21
+ safe_yaml (~> 0.9.0)
22
+ diff-lcs (1.2.5)
23
+ docile (1.1.0)
24
+ faraday (0.8.8)
25
+ multipart-post (~> 1.2.0)
26
+ git (1.2.6)
27
+ github_api (0.10.1)
28
+ addressable
29
+ faraday (~> 0.8.1)
30
+ hashie (>= 1.2)
31
+ multi_json (~> 1.4)
32
+ nokogiri (~> 1.5.2)
33
+ oauth2
34
+ hashie (2.0.5)
35
+ highline (1.6.20)
36
+ httparty (0.12.0)
37
+ json (~> 1.8)
38
+ multi_xml (>= 0.5.2)
39
+ httpauth (0.2.0)
40
+ i18n (0.6.5)
41
+ jeweler (1.8.8)
42
+ builder
43
+ bundler (~> 1.0)
44
+ git (>= 1.2.5)
45
+ github_api (= 0.10.1)
46
+ highline (>= 1.6.15)
47
+ nokogiri (= 1.5.10)
48
+ rake
49
+ rdoc
50
+ json (1.8.1)
51
+ jwt (0.1.8)
52
+ multi_json (>= 1.5)
53
+ method_source (0.8.2)
54
+ mime-types (2.0)
55
+ minitest (4.7.5)
56
+ multi_json (1.8.2)
57
+ multi_xml (0.5.5)
58
+ multipart-post (1.2.0)
59
+ nokogiri (1.5.10)
60
+ oauth2 (0.9.2)
61
+ faraday (~> 0.8)
62
+ httpauth (~> 0.2)
63
+ jwt (~> 0.1.4)
64
+ multi_json (~> 1.0)
65
+ multi_xml (~> 0.5)
66
+ rack (~> 1.2)
67
+ pry (0.9.12.4)
68
+ coderay (~> 1.0)
69
+ method_source (~> 0.8)
70
+ slop (~> 3.4)
71
+ rack (1.5.2)
72
+ rake (10.1.0)
73
+ rdoc (3.12.2)
74
+ json (~> 1.4)
75
+ rest-client (1.6.7)
76
+ mime-types (>= 1.16)
77
+ rspec (2.14.1)
78
+ rspec-core (~> 2.14.0)
79
+ rspec-expectations (~> 2.14.0)
80
+ rspec-mocks (~> 2.14.0)
81
+ rspec-core (2.14.7)
82
+ rspec-expectations (2.14.4)
83
+ diff-lcs (>= 1.1.3, < 2.0)
84
+ rspec-mocks (2.14.4)
85
+ safe_yaml (0.9.7)
86
+ shoulda (3.5.0)
87
+ shoulda-context (~> 1.0, >= 1.0.1)
88
+ shoulda-matchers (>= 1.4.1, < 3.0)
89
+ shoulda-context (1.1.6)
90
+ shoulda-matchers (2.4.0)
91
+ activesupport (>= 3.0.0)
92
+ simplecov (0.8.2)
93
+ docile (~> 1.1.0)
94
+ multi_json
95
+ simplecov-html (~> 0.8.0)
96
+ simplecov-html (0.8.0)
97
+ slop (3.4.7)
98
+ term-ansicolor (1.2.2)
99
+ tins (~> 0.8)
100
+ thor (0.18.1)
101
+ thread_safe (0.1.3)
102
+ atomic
103
+ tins (0.12.0)
104
+ tzinfo (0.3.38)
105
+ webmock (1.15.0)
106
+ addressable (>= 2.2.7)
107
+ crack (>= 0.3.2)
108
+
109
+ PLATFORMS
110
+ ruby
111
+
112
+ DEPENDENCIES
113
+ bundler (~> 1.0)
114
+ coveralls
115
+ httparty
116
+ jeweler (~> 1.8.7)
117
+ pry
118
+ rake
119
+ rdoc (~> 3.12)
120
+ rspec
121
+ shoulda
122
+ shoulda-matchers
123
+ simplecov
124
+ webmock
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
- Copyright (c) 2013 Dan Crews
2
-
3
1
  MIT License
2
+ =======
3
+ Copyright (c) 2013 Abby Howell and Dan Crews
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,26 +1,93 @@
1
- # Rubykhan
2
1
 
3
- TODO: Write a gem description
2
+ # RubyKhan: a Khan Academy API gem
4
3
 
5
- ## Installation
6
4
 
7
- Add this line to your application's Gemfile:
5
+ [![Gem Version](https://badge.fury.io/rb/rubykhan.png)](http://badge.fury.io/rb/rubykhan)
8
6
 
9
- gem 'rubykhan'
7
+ [![Coverage Status](https://coveralls.io/repos/abigezunt/rubykhan/badge.png)](https://coveralls.io/r/abigezunt/rubykhan)
10
8
 
11
- And then execute:
9
+ [![Build Status](https://travis-ci.org/abigezunt/rubykhan.png?branch=master)](https://travis-ci.org/abigezunt/rubykhan)
12
10
 
13
- $ bundle
11
+ [![Code Climate](https://codeclimate.com/github/abigezunt/rubykhan.png)](https://codeclimate.com/github/abigezunt/rubykhan)
14
12
 
15
- Or install it yourself as:
13
+ ```ruby
14
+ gem 'rubykhan'
15
+ ```
16
16
 
17
- $ gem install rubykhan
17
+ ```ruby
18
+ require 'rubykhan'
19
+ ```
18
20
 
19
- ## Usage
21
+ ## Accessing the Khan Academy API
20
22
 
21
- TODO: Write usage instructions here
23
+ Information from Khan academy's API is accessed through topic keywords called "slugs" that you can use in your API requests. Topics are arranged hierarchically from the most general (e.g. "math", "science", "humanities") to the very specific.
22
24
 
23
- ## Contributing
25
+ To see the whole topic tree hash, you can instantiate a Topic Tree object:
26
+
27
+ ```ruby
28
+ all = KhanAcademy::TopicTree.new
29
+ ```
30
+
31
+ And you can inspect the whole hierarchy to see what is returned via json:
32
+
33
+ ```ruby
34
+ all.topictree
35
+ ```
36
+
37
+ You can also retrieve a hash of just the topic slugs to choose from for your further queries:
38
+
39
+ ```ruby
40
+ all.topics
41
+ ```
42
+
43
+ Another API query returns more detailed information about a topic, including its children, which can be other, more specific topics, or videos and exercises. The most specific sub-sub-topics have videos and exercises, but the top-level topics don't, so you won't get any exercises for a topic like "math" or even something as specific as "algebra", but the topic "solving-linear-equations-and-inequalities does return some exercises. It sometimes takes several queries to get to that level.
44
+
45
+ To query about a topic, instantiate a topic object:
46
+
47
+ ```ruby
48
+ getty_museum = KhanAcademy::Topic.new('getty-museum')
49
+ ```
50
+
51
+ You can access the json response directly with the `.json` method:
52
+
53
+ ```ruby
54
+ getty_museum.json
55
+ ```
56
+
57
+ You can also access many attributes with ruby attribute accessor methods:
58
+
59
+ ```ruby
60
+ description = getty_museum.description
61
+ title = getty_museum.title
62
+ url = getty_museum.url
63
+ parent_topic = getty_museum.parent_topic
64
+ ```
65
+
66
+ To see the list of related subtopics and videos:
67
+
68
+ ```ruby
69
+ children = getty_museum.children
70
+ ```
71
+
72
+ ```ruby
73
+ algebra = KhanAcademy::Topic.new('algebra')
74
+ algebra.subtopics
75
+ ```
76
+
77
+ ```ruby
78
+ linear_equations = KhanAcademy::Topic.new('solving-linear-equations-and-inequalities')
79
+ linear_equations.subtopics
80
+ ```
81
+
82
+ More information about the Khan Academy API can be found at the [Khan Academy API Explorer](http://api-explorer.khanacademy.org/api/v1/).
83
+
84
+ ## FAQ:
85
+
86
+ Q: What's up with the name?
87
+
88
+ A: It's a pun on [Crossing the Rubicon](https://www.khanacademy.org/humanities/history/ancient-medieval/Ancient/v/a-tour-through-ancient-rome-in-320-c-e). Julius Caesar would've used Ruby in his conquest of Gaul, and we want you to be able to use Ruby in your Khan Academy app. :)
89
+
90
+ ## CONTRIBUTING
24
91
 
25
92
  1. Fork it
26
93
  2. Create your feature branch (`git checkout -b my-new-feature`)
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ # Pulls in equiv of 'rspec spec' to be 'rake spec'
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ # If you just run 'rake', it will run 'rake spec'
9
+ task test: :spec
10
+ task default: :spec
data/config.ru ADDED
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
File without changes
@@ -1,3 +1,3 @@
1
1
  module Rubykhan
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/rubykhan.rb CHANGED
@@ -1,22 +1,138 @@
1
- require 'rubykhan/client'
2
-
3
- module Rubykhan
4
- class << self
5
- # attr_accessor :key
6
- def configure
7
- yield self
8
- end
9
-
10
- def new
11
- end
12
-
13
- def method_missing(method, *args, &block)
14
- return super unless new.respond_to?(method)
15
- new.send(method, *args, &block)
16
- end
17
-
18
- def respond_to?(method, include_private=false)
19
- new.respond_to?(method, include_private) || super(method, include_private)
20
- end
21
- end
1
+ # require 'rubykhan/client'
2
+
3
+ # module Rubykhan
4
+ # class << self
5
+ # # attr_accessor :key
6
+ # def configure
7
+ # yield self
8
+ # end
9
+
10
+ # def new
11
+ # end
12
+
13
+ # def method_missing(method, *args, &block)
14
+ # return super unless new.respond_to?(method)
15
+ # new.send(method, *args, &block)
16
+ # end
17
+
18
+ # def respond_to?(method, include_private=false)
19
+ # new.respond_to?(method, include_private) || super(method, include_private)
20
+ # end
21
+ # end
22
+ # end
23
+ require 'pry'
24
+ require 'httparty'
25
+ require 'json'
26
+
27
+ module KhanAcademy
28
+
29
+
30
+ class TopicTree
31
+ attr_reader :topictree
32
+
33
+ def initialize
34
+ @topictree = HTTParty.get('http://www.khanacademy.org/api/v1/topictree')
35
+ end
36
+
37
+ def topics
38
+ @main_topics = @topictree['children'].map { |topic| topic['slug']}
39
+ topics = {}
40
+ @main_topics.each_with_index do |topic, index|
41
+ topics[topic] = @topictree['children'][index]['children'].map {|subtopic| subtopic['slug']}
42
+ end
43
+ return topics
44
+ end
45
+
46
+ end
47
+
48
+
49
+ class Topic
50
+ attr_reader :json
51
+
52
+ def initialize(topic_slug)
53
+ @topic_slug = topic_slug
54
+ @json = HTTParty.get("http://www.KhanAcademy.org/api/v1/topic/#{@topic_slug}")
55
+ end
56
+
57
+ def title
58
+ @json['title']
59
+ end
60
+
61
+ def children
62
+ @json['children']
63
+ end
64
+
65
+ def kind
66
+ @json['kind']
67
+ end
68
+
69
+ def standalone_title
70
+ @json['standalone_title']
71
+ end
72
+
73
+ def description
74
+ @json['description']
75
+ end
76
+
77
+ def slug
78
+ @json['slug']
79
+ end
80
+
81
+ def node_slug
82
+ @json['node_slug']
83
+ end
84
+
85
+ def extended_slug
86
+ @json['extended_slug']
87
+ end
88
+
89
+ def facebook_url
90
+ @json['facebook_url']
91
+ end
92
+
93
+ def twitter_url
94
+ @json['twitter_url']
95
+ end
96
+
97
+ def web_url
98
+ @json['web_url']
99
+ end
100
+
101
+ def ka_url
102
+ @json['ka_url']
103
+ end
104
+
105
+ def url
106
+ @json['url'] || @json['ka_url'] || @json['web_url']
107
+ end
108
+
109
+ def topic_page_url
110
+ @json['topic_page_url']
111
+ end
112
+
113
+ def subtopics_count
114
+ @json.children.count
115
+ end
116
+
117
+ def parent_topic
118
+ @json['domain_slug']
119
+ end
120
+
121
+ def icon_src
122
+ @json['icon_src']
123
+ end
124
+
125
+ def subtopics
126
+ @json['children'].map do |topic|
127
+ {title: topic['title'],
128
+ url: topic['url'],
129
+ internal_id: topic['internal_id'],
130
+ node_slug: topic['node_slug'],
131
+ translated_title: topic['translated_title'],
132
+ id: topic['id'],
133
+ kind: topic['kind']}
134
+ end
135
+ end
136
+
137
+ end
22
138
  end
data/lib/topics.rb ADDED
@@ -0,0 +1,100 @@
1
+
2
+ # class Topic
3
+ # attr_reader :topic_slug, :data, :url, :id, :children, :slug, :kind, :tags, :url, :title, :node_slug, :subtopics
4
+ # def initialize(topic_slug)
5
+ # @topic_slug = topic_slug
6
+ # @data = HTTParty.get("http://www.KhanAcademy.org/api/v1/topic/#{@topic_slug}")
7
+ # @ka_url = @data['ka_url']
8
+ # @id = @data['id']
9
+ # @children = @data['children']
10
+ # @slug = @data['slug']
11
+ # @kind = @data['kind']
12
+ # @tags = @data['tags']
13
+ # @url = @data['url']
14
+ # @title = @data['title']
15
+ # @node_slug = @data['node_slug']
16
+ # @internal_id = data['internal_id']
17
+ # @url = data['url']
18
+ # @node_slug = data['node_slug']
19
+ # @edit_slug = data['edit_slug']
20
+ # @key = data['key']
21
+ # @translated_title = data['translated_title']
22
+ # if data['children']
23
+ # @children = data['children']
24
+ # @subtopics = []
25
+ # @videos = []
26
+ # @exercises = []
27
+ # instantiate_subtopics
28
+ # end
29
+
30
+ # end
31
+
32
+ # private
33
+
34
+ # def instantiate_subtopics
35
+
36
+ # @children.each do |child|
37
+ # case child['kind']
38
+ # when "Topic"
39
+ # begin
40
+ # @subtopics << KhanAcademy::Topic.new(child['id'])
41
+ # rescue
42
+ # @subtopics << KhanAcademy::Subtopic.new(child)
43
+ # end
44
+ # when "Video"
45
+ # @videos << KhanAcademy::Video.new(child)
46
+ # when "Exercise"
47
+ # @exercises << KhanAcademy::Exercise.new(child)
48
+ # end
49
+ # end
50
+ # end
51
+ # end
52
+
53
+ # class Subtopic
54
+ # attr_reader :data, :kind, :internal_id, :title, :url, :node_slug, :edit_slug, :key, :translated_title, :id
55
+ # def initialize(data)
56
+ # @data = data
57
+ # @kind = data['kind']
58
+ # @internal_id = data['internal_id']
59
+ # @title = data['title']
60
+ # @url = data['url']
61
+ # @node_slug = data['node_slug']
62
+ # @edit_slug = data['edit_slug']
63
+ # @key = data['key']
64
+ # @translated_title = data['translated_title']
65
+ # @id = data['id']
66
+ # end
67
+
68
+ # end
69
+
70
+ # class Video
71
+ # def initialize(data)
72
+ # @kind = data['kind']
73
+ # @internal_id = data['internal_id']
74
+ # @title = data['title']
75
+ # @url = data['url']
76
+ # @node_slug = data['node_slug']
77
+ # @edit_slug = data['edit_slug']
78
+ # @key = data['key']
79
+ # @translated_title = data['translated_title']
80
+ # @id = data['id']
81
+ # end
82
+ # end
83
+
84
+ # class Exercise
85
+ # def initialize(data)
86
+ # @kind = data['kind']
87
+ # @internal_id = data['internal_id']
88
+ # @title = data['title']
89
+ # @url = data['url']
90
+ # @node_slug = data['node_slug']
91
+ # @edit_slug = data['edit_slug']
92
+ # @key = data['key']
93
+ # @translated_title = data['translated_title']
94
+ # @id = data['id']
95
+ # end
96
+ # end
97
+
98
+ # end
99
+
100
+
@@ -0,0 +1,17 @@
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
data/rubykhan/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubykhan.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dan Crews
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,29 @@
1
+ # Rubykhan
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rubykhan'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rubykhan
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/rubykhan/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module Rubykhan
2
+ VERSION = "0.0.1"
3
+ end