lingorb 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b4d60da05efe50121047761143b17a6295d23b5b79e24db2e9c2563dea584395
4
+ data.tar.gz: 2a9feaeeb3137a509ae10e7765ab773ea9ad91dd08ca8b8da0d839a886c9f605
5
+ SHA512:
6
+ metadata.gz: be74d43cd9984a66474f6c8e0386c695af5849cf4eda5c15e06c5d07cb583f44a75c3fe15d7cc7cd4ffd0c38677136323b654b1ad3c2b4144f7b5382456ebdcb
7
+ data.tar.gz: 69d30069d4f35691ee40e10db44e262ef3f2106c41488304580ae4081967312330b3d3dcc333f73d24a841d748f14ecbff5e149b49eb413361b6c75be6edeaae
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in lingorb.gemspec
4
+ gemspec
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lingorb (0.0.1.pre)
5
+ faraday (~> 0.15)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ faraday (0.15.4)
11
+ multipart-post (>= 1.2, < 3)
12
+ multipart-post (2.1.1)
13
+ rake (10.5.0)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (~> 2.0)
20
+ lingorb!
21
+ rake (~> 10.0)
22
+
23
+ BUNDLED WITH
24
+ 2.0.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Uchio Kondo
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,46 @@
1
+ # Lingorb
2
+
3
+ Yet another duoling unofficial API binding. This is a port of https://github.com/KartikTalwar/Duolingo !
4
+
5
+ Released rubygem `duolingo` is too old and not following current unofficial API spec, so I recreated.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'lingorb'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install lingorb
22
+
23
+ ## Usage
24
+
25
+ !!!TODO: Write usage instructions here!!!
26
+
27
+ ```ruby
28
+ # I want Ruby API like that
29
+ cli = Lingorb.authenticate(@user, @passwd)
30
+ user = cli.current_user
31
+ p user.gain_xp_history
32
+ ```
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/udzura/lingorb.
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lingorb"
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
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "lingorb"
@@ -0,0 +1,18 @@
1
+ require "lingorb/version"
2
+ require "lingorb/client"
3
+
4
+ module Lingorb
5
+ def self.authenticate(username=nil, password=nil, &b)
6
+ c = nil
7
+ if b
8
+ mock = Struct.new(:username, :password).new
9
+ b.call(mock)
10
+ c = Client.new(mock.username, mock.password)
11
+ else
12
+ c = Client.new(username, password)
13
+ end
14
+
15
+ c.login
16
+ c
17
+ end
18
+ end
@@ -0,0 +1,63 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Lingorb
5
+ DUOLINGO_ROOT_URL = 'https://www.duolingo.com/'
6
+ DUOLINGO_API_VERSION = '2017-06-30'
7
+
8
+ class ClientError < StandardError; end
9
+
10
+ class Client
11
+ def initialize(username, password)
12
+ @username, @password = username, password
13
+ @conn = Faraday.new(url: DUOLINGO_ROOT_URL)
14
+ @jwt = nil
15
+ @current_user = nil
16
+ end
17
+
18
+ def login
19
+ res = @conn.post "#{DUOLINGO_ROOT_URL}/login" do |req|
20
+ req.headers['Content-Type'] = 'application/json'
21
+ req.body = {"login" => @username, "password" => @password}.to_json
22
+ end
23
+ body = JSON.parse(res.body)
24
+ # I want to do pattern match!!
25
+ if body["failure"]
26
+ raise ClientError, "Login failed: code=%s, %s" % [body["failure"], body["message"]]
27
+ else
28
+ @jwt = res.headers["jwt"]
29
+ end
30
+ end
31
+
32
+ def current_user
33
+ return @current_user if @current_user
34
+
35
+ user_url = "#{DUOLINGO_API_VERSION}/users?username=%s" % @username
36
+ res = @conn.get user_url do |req|
37
+ # req.headers['Authorization'] = "Bearer #{@jwt}" if @jwt
38
+ end
39
+ @current_user ||= User.new(JSON.parse(res.body), @conn)
40
+ end
41
+ end
42
+
43
+ class User
44
+ def initialize(data, conn)
45
+ @conn = conn
46
+ @data = data
47
+ @id = data["users"][0]["id"]
48
+ @username = data["users"][0]["username"]
49
+ @bio = data["users"][0]["bio"]
50
+ @location = data["users"][0]["location"]
51
+ @learning_language = data["users"][0]["leraningLanguage"]
52
+ @from_language = data["users"][0]["fromLanguage"]
53
+ @streak = data["users"][0]["streak"]
54
+ end
55
+ attr_accessor :id,
56
+ :username,
57
+ :bio,
58
+ :location,
59
+ :learning_language,
60
+ :from_language,
61
+ :streak
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module Lingorb
2
+ VERSION = "0.0.1.pre"
3
+ end
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "lingorb/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "lingorb"
7
+ spec.version = Lingorb::VERSION
8
+ spec.authors = ["Uchio Kondo"]
9
+ spec.email = ["udzura@udzura.jp"]
10
+
11
+ spec.summary = %q{Yet another duoling unofficial API binding}
12
+ spec.description = %q{Yet another duoling unofficial API binding}
13
+ spec.homepage = "https://github.com/udzura/lingorb"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_runtime_dependency "faraday", "~> 0.15"
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lingorb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ platform: ruby
6
+ authors:
7
+ - Uchio Kondo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
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
+ description: Yet another duoling unofficial API binding
56
+ email:
57
+ - udzura@udzura.jp
58
+ executables:
59
+ - lingorb
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - exe/lingorb
72
+ - lib/lingorb.rb
73
+ - lib/lingorb/client.rb
74
+ - lib/lingorb/version.rb
75
+ - lingorb.gemspec
76
+ homepage: https://github.com/udzura/lingorb
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">"
92
+ - !ruby/object:Gem::Version
93
+ version: 1.3.1
94
+ requirements: []
95
+ rubygems_version: 3.0.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Yet another duoling unofficial API binding
99
+ test_files: []