learn-web 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3b5797e4cb835892ff9f53b90df7b06a8594649
4
+ data.tar.gz: 0b07148cedfadf55d45130692fd38a826467dc52
5
+ SHA512:
6
+ metadata.gz: 3c98adaad7d5889f3982db1422b47cfecc21ceab4a6eb1ed093c3746261ffc18298d1295279e4ced7fe3a91206c8f75718efb755c1039031bf722d7727c1196e
7
+ data.tar.gz: a5482e5668650e9df2c644905fa801aa26008dee9c3bbb91f61534270825df57f388e3887710f19bffe5f16906093e4c65a3831a4694d4b9134bde26d19366fa
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in learn-submit.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Flatiron School
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # learn-web
2
+
3
+ Handles submitting Learn.co lessons.
4
+
5
+ ## Installation
6
+
7
+ Install with:
8
+
9
+ ```
10
+ $ gem install learn-web
11
+ ```
12
+
13
+ Alternatively, add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'learn-web'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/flatiron-labs/learn-web/fork )
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 a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/learn-submit ADDED
File without changes
data/learn-web.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'learn_web/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "learn-web"
8
+ spec.version = LearnWeb::VERSION
9
+ spec.authors = ["Flatiron School"]
10
+ spec.email = ["learn@flatironschool.com"]
11
+ spec.summary = %q{An interface to Learn.co}
12
+ spec.homepage = "https://learn.co"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+
23
+ spec.add_runtime_dependency "faraday", "~> 0.9"
24
+ spec.add_runtime_dependency "oj", "~> 2.9"
25
+ end
data/lib/learn_web.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'learn_web/version'
2
+ require 'learn_web/client'
3
+ require 'learn_web/client/me'
4
+
5
+ module LearnWeb
6
+ end
@@ -0,0 +1,35 @@
1
+ require 'faraday'
2
+
3
+ module LearnWeb
4
+ class Client
5
+ attr_reader :token, :conn, :silent_output
6
+
7
+ LEARN_URL = 'https://learn.co'
8
+ API_ROOT = '/api/v1'
9
+
10
+ def initialize(token:, silent_output: false)
11
+ @token = token
12
+ @silent_output = silent_output
13
+ @conn = Faraday.new(url: LEARN_URL) do |faraday|
14
+ faraday.adapter Faraday.default_adapter
15
+ end
16
+ end
17
+
18
+ def me_endpoint
19
+ "#{API_ROOT}/users/me"
20
+ end
21
+
22
+ def me
23
+ response = @conn.get do |req|
24
+ req.url me_endpoint
25
+ req.headers['Authorization'] = "Bearer #{token}"
26
+ end
27
+
28
+ LearnWeb::Client::Me.new(response, silent_output: silent_output)
29
+ end
30
+
31
+ def valid_token?
32
+ !!me.data
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,54 @@
1
+ require 'oj'
2
+
3
+ module LearnWeb
4
+ module Client
5
+ class Me
6
+ attr_accessor :response, :id, :first_name, :last_name, :full_name,
7
+ :username, :email, :github_gravatar, :github_uid, :data,
8
+ :silent_output
9
+
10
+ def initialize(response, silent_output: false)
11
+ @response = response
12
+ @silent_output = silent_output
13
+
14
+ parse!
15
+ end
16
+
17
+ def parse!
18
+ if response.status == 200
19
+ self.data = Oj.load(response.body, symbol_keys: true)
20
+
21
+ populate_attributes!
22
+ elsif silent_output == false
23
+ case response.status
24
+ when 401
25
+ puts "It seems your OAuth token is incorrect. Please re-run config with: learn reset"
26
+ exit
27
+ when 500
28
+ puts "Something went wrong. Please try again."
29
+ exit
30
+ else
31
+ puts "Something went wrong. Please try again."
32
+ exit
33
+ end
34
+ end
35
+
36
+ self
37
+ end
38
+
39
+ private
40
+
41
+ def populate_attributes!
42
+ data.each do |attribute, value|
43
+ if !self.respond_to?(attribute)
44
+ class << self
45
+ attr_accessor attribute
46
+ end
47
+ end
48
+
49
+ self.send("#{attribute}=", value)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module LearnWeb
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: learn-web
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Flatiron School
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: oj
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.9'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.9'
69
+ description:
70
+ email:
71
+ - learn@flatironschool.com
72
+ executables:
73
+ - learn-submit
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/learn-submit
83
+ - learn-web.gemspec
84
+ - lib/learn_web.rb
85
+ - lib/learn_web/client.rb
86
+ - lib/learn_web/client/me.rb
87
+ - lib/learn_web/version.rb
88
+ homepage: https://learn.co
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.5
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: An interface to Learn.co
112
+ test_files: []