teachable-jg 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/Rakefile +11 -1
- data/bin/console +2 -2
- data/lib/teachable/jg/client.rb +51 -11
- data/lib/teachable/jg/configuration.rb +17 -15
- data/lib/teachable/jg/version.rb +1 -1
- data/teachable-jg.gemspec +3 -0
- metadata +44 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b9eb0e5665cab09e9030363f7b209beb16571e4
|
4
|
+
data.tar.gz: 5bbbdd2a1d1ab0aab270b1ec6c6f43c3456b3b63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a94f0abfa77f3d80d94ad79332e48941438b6119bcc6b1e82a66a858bc2d4ca470b4c9d70733b23dc704037610a54750a17e6145b734cad59915cacf2e0ec38c
|
7
|
+
data.tar.gz: 73e14225826732136131abc1eb3bd400f4566cce3ef258e0bcedf9abce8ddfb3b18f4ea6ea0f916406b22ef6a28853092ca3a24e45d76a35f424f0946a95f369
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/lib/teachable/jg/client.rb
CHANGED
@@ -1,29 +1,69 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
1
3
|
module Teachable
|
2
4
|
module Jg
|
3
5
|
class Client
|
6
|
+
include HTTParty
|
4
7
|
|
5
|
-
|
6
|
-
attr_accessor *Configuration::VALID_CONFIG_KEYS
|
7
|
-
|
8
|
-
# self.base_uri "https://#{CREDENTIALS[:host]}/#{CREDENTIALS[:path]}/Accounts/#{CREDENTIALS[:account_id]}"
|
8
|
+
format :json
|
9
9
|
|
10
|
+
SUCCESSFUL_LOGIN = {"success"=>true, "login"=>"verified"}
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
# Define the same set of accessors as the Teachable module
|
13
|
+
attr_accessor *Teachable::Jg::Configuration::VALID_CONFIG_KEYS
|
14
|
+
attr_accessor :endpoint
|
14
15
|
|
16
|
+
# curl -X POST -d '{ "user": { "email": "dev-8@example.com", "password": "password" }}' localhost:3000/users/sign_in.json -i -H "Accept: application/json" -H "Content-Type: application/json"
|
15
17
|
def initialize(options={})
|
16
|
-
# Merge the config values from the module and those passed
|
17
|
-
# to the client.
|
18
|
+
# # Merge the config values from the module and those passed
|
19
|
+
# # to the client.
|
20
|
+
|
18
21
|
merged_options = Teachable::Jg.options.merge(options)
|
19
22
|
|
20
23
|
# Copy the merged values to this client and ignore those
|
21
24
|
# not part of our configuration
|
22
|
-
Configuration::VALID_CONFIG_KEYS.each do |key|
|
25
|
+
Teachable::Jg::Configuration::VALID_CONFIG_KEYS.each do |key|
|
23
26
|
send("#{key}=", merged_options[key])
|
24
27
|
end
|
28
|
+
@endpoint = Teachable::Jg::Configuration::DEFAULT_ENDPOINT
|
29
|
+
@authorization_message = authorize(options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def authorize(options={})
|
33
|
+
path = @endpoint + "/sign-in"
|
34
|
+
|
35
|
+
query = {user: {
|
36
|
+
"email" => options[:email],
|
37
|
+
"password" => options[:password],
|
38
|
+
}}
|
39
|
+
|
40
|
+
headers = {
|
41
|
+
"Accept" => "application/json",
|
42
|
+
"Content-Type" => "application/json"
|
43
|
+
}
|
44
|
+
|
45
|
+
resp = HTTParty.post(
|
46
|
+
path,
|
47
|
+
query: query,
|
48
|
+
headers: headers
|
49
|
+
)
|
50
|
+
|
51
|
+
body = process_body(resp.body)
|
52
|
+
|
53
|
+
@authorized = true if body == SUCCESSFUL_LOGIN
|
54
|
+
|
55
|
+
return body
|
56
|
+
end
|
57
|
+
|
58
|
+
def process_body(body)
|
59
|
+
if body.is_a?(String)
|
60
|
+
JSON.parse(body)
|
61
|
+
else
|
62
|
+
{"success"=>false, "login"=>"no json response"}
|
63
|
+
end
|
25
64
|
end
|
26
65
|
|
27
66
|
end # Client
|
28
67
|
end
|
29
|
-
end
|
68
|
+
end
|
69
|
+
|
@@ -1,16 +1,17 @@
|
|
1
1
|
module Teachable
|
2
2
|
module Jg
|
3
3
|
module Configuration
|
4
|
-
VALID_CONNECTION_KEYS
|
5
|
-
VALID_OPTIONS_KEYS
|
6
|
-
VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
|
4
|
+
VALID_CONNECTION_KEYS = [:method, :authorization_message, :authorized].freeze
|
5
|
+
VALID_OPTIONS_KEYS = [:format].freeze
|
7
6
|
|
8
|
-
|
9
|
-
DEFAULT_METHOD = :get
|
10
|
-
DEFAULT_USER_AGENT = "Teachable API Ruby Gem #{Teachable::Jg::VERSION}".freeze
|
7
|
+
VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
|
11
8
|
|
12
|
-
|
13
|
-
|
9
|
+
DEFAULT_ENDPOINT = 'http://secure.localhost.com:3000/users'
|
10
|
+
DEFAULT_METHOD = :post
|
11
|
+
DEFAULT_USER_AGENT = "Teachable API Ruby Gem #{Teachable::Jg::VERSION}".freeze
|
12
|
+
DEFAULT_FORMAT = :json
|
13
|
+
DEFAULT_AUTHORIZED = false
|
14
|
+
DEFAULT_AUTHORIZATION_MESSAGE = ""
|
14
15
|
|
15
16
|
# Build accessor methods for every config options so we can do this, for example:
|
16
17
|
# Teachable::Jg.format = :xml
|
@@ -22,16 +23,17 @@ module Teachable
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def options
|
25
|
-
Hash[ * VALID_CONFIG_KEYS.map
|
26
|
+
Hash[ * VALID_CONFIG_KEYS.map do |key|
|
27
|
+
self.reset
|
28
|
+
[key, send(key)]
|
29
|
+
end.flatten ]
|
26
30
|
end
|
27
31
|
|
28
32
|
def reset
|
29
|
-
self.
|
30
|
-
self.
|
31
|
-
self.
|
32
|
-
|
33
|
-
self.api_key = DEFAULT_API_KEY
|
34
|
-
self.format = DEFAULT_FORMAT
|
33
|
+
self.method = DEFAULT_METHOD
|
34
|
+
self.format = DEFAULT_FORMAT
|
35
|
+
self.authorized = DEFAULT_AUTHORIZED
|
36
|
+
self.authorization_message = DEFAULT_AUTHORIZATION_MESSAGE
|
35
37
|
end
|
36
38
|
|
37
39
|
def configure
|
data/lib/teachable/jg/version.rb
CHANGED
data/teachable-jg.gemspec
CHANGED
@@ -24,4 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "rake", "~> 12.0"
|
25
25
|
spec.add_development_dependency "pry"
|
26
26
|
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "httparty"
|
28
|
+
spec.add_development_dependency "vcr"
|
29
|
+
spec.add_development_dependency "webmock", "1.24.2"
|
27
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teachable-jg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,48 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.24.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.24.2
|
69
111
|
description: A convenient wrapper for the valid endpoints of Teachable Mock API
|
70
112
|
email:
|
71
113
|
- joshua.guthals@gmail.com
|