teachable-jg 0.0.4 → 0.0.5
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/lib/teachable/jg/client.rb +43 -9
- data/lib/teachable/jg/configuration.rb +17 -13
- data/lib/teachable/jg/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82dcfd7be7c363d988e8c6e0a04700b1931d524d
|
4
|
+
data.tar.gz: a266cc103e6a9cd031c703f4aaf7db50cf75fe93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4c9b3644c1bdf706772fd4d63b52fdc599b3f749738a0bec53aed1daa5ccab34c1289ac59aceab676ec812f789eb0900828d96b0d9bae29c18a6e908eb2fabd
|
7
|
+
data.tar.gz: 5793a206433d2b407ac7425c14407a900427b2eeb34972be1a111f18fef06966c4c2e52b83e5bd8c56ab5864f9528af97d73472eda1d9434a586266aaa79abea
|
data/lib/teachable/jg/client.rb
CHANGED
@@ -7,22 +7,17 @@ module Teachable
|
|
7
7
|
|
8
8
|
format :json
|
9
9
|
|
10
|
-
SUCCESSFUL_LOGIN = {"success"=>true, "login"=>"verified"}
|
11
|
-
SUCCESSFUL_REGISTRATION = {"success"=>true, "registration"=>"verified"}
|
10
|
+
# SUCCESSFUL_LOGIN = {"success"=>true, "login"=>"verified"}
|
11
|
+
# SUCCESSFUL_REGISTRATION = {"success"=>true, "registration"=>"verified"}
|
12
12
|
|
13
13
|
# Define the same set of accessors as the Teachable module
|
14
14
|
attr_accessor *Teachable::Jg::Configuration::VALID_CONFIG_KEYS
|
15
|
-
attr_accessor :endpoint
|
15
|
+
attr_accessor :endpoint, :authorized
|
16
16
|
|
17
17
|
# 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"
|
18
18
|
def initialize(options={})
|
19
|
-
# # Merge the config values from the module and those passed
|
20
|
-
# # to the client.
|
21
|
-
|
22
19
|
merged_options = Teachable::Jg.options.merge(options)
|
23
20
|
|
24
|
-
# Copy the merged values to this client and ignore those
|
25
|
-
# not part of our configuration
|
26
21
|
Teachable::Jg::Configuration::VALID_CONFIG_KEYS.each do |key|
|
27
22
|
send("#{key}=", merged_options[key])
|
28
23
|
end
|
@@ -57,7 +52,8 @@ module Teachable
|
|
57
52
|
if resp.code == 200
|
58
53
|
body = process_body(resp.body)
|
59
54
|
|
60
|
-
self.
|
55
|
+
self.delivered = true if body["success"]
|
56
|
+
self.authorized = true if body["login"] == "verified"
|
61
57
|
|
62
58
|
return body
|
63
59
|
else
|
@@ -73,6 +69,44 @@ module Teachable
|
|
73
69
|
end
|
74
70
|
end
|
75
71
|
|
72
|
+
def get_user_info(path, options)
|
73
|
+
user_headers = headers.reject {|key| key == "Accept" }
|
74
|
+
|
75
|
+
query = {
|
76
|
+
user_email: options[:user_email],
|
77
|
+
user_token: options[:user_token]
|
78
|
+
}
|
79
|
+
|
80
|
+
resp = HTTParty.get(
|
81
|
+
path,
|
82
|
+
query: query,
|
83
|
+
headers: user_headers
|
84
|
+
)
|
85
|
+
|
86
|
+
if resp.code == 200
|
87
|
+
body = process_body(resp.body)
|
88
|
+
self.delivered = true if body["success"]
|
89
|
+
return body
|
90
|
+
else
|
91
|
+
return resp.code
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def user_info(options={})
|
96
|
+
if authorized
|
97
|
+
path = options[:path] || Teachable::Jg::Configuration::CURRENT_USER_ENDPOINT
|
98
|
+
if options[:user_email] && !options[:user_email].nil? && options[:user_token] && !options[:user_token].nil?
|
99
|
+
resp = get_user_info(path, options)
|
100
|
+
else
|
101
|
+
self.delivered = false
|
102
|
+
{"success"=>false, "user_info"=>"missing or invalid params"}
|
103
|
+
end
|
104
|
+
else
|
105
|
+
self.delivered = false
|
106
|
+
{"success"=>false, "login"=>"failed to authorize"}
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
76
110
|
end # Client
|
77
111
|
end
|
78
112
|
end
|
@@ -1,20 +1,23 @@
|
|
1
1
|
module Teachable
|
2
2
|
module Jg
|
3
3
|
module Configuration
|
4
|
-
VALID_CONNECTION_KEYS
|
5
|
-
VALID_OPTIONS_KEYS
|
6
|
-
|
7
|
-
VALID_CONFIG_KEYS
|
8
|
-
|
9
|
-
DEFAULT_ENDPOINT
|
10
|
-
DEFAULT_METHOD
|
11
|
-
DEFAULT_USER_AGENT
|
12
|
-
DEFAULT_FORMAT
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
VALID_CONNECTION_KEYS = [:method, :status_message, :delivered].freeze
|
5
|
+
VALID_OPTIONS_KEYS = [:format, :headers, :authorized].freeze
|
6
|
+
|
7
|
+
VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
|
8
|
+
|
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_DELIVERED = false
|
14
|
+
DEFAULT_AUTHORIZED = false
|
15
|
+
DEFAULT_HEADERS = { "Content-Type" => "application/json",
|
16
|
+
"Accept" => "application/json" }
|
16
17
|
DEFAULT_STATUS_MESSAGE = ""
|
17
18
|
|
19
|
+
CURRENT_USER_ENDPOINT = "http://secure.localhost.com:3000/api/users/current_user/edit"
|
20
|
+
|
18
21
|
# Build accessor methods for every config options so we can do this, for example:
|
19
22
|
# Teachable::Jg.format = :xml
|
20
23
|
attr_accessor *VALID_CONFIG_KEYS
|
@@ -34,9 +37,10 @@ module Teachable
|
|
34
37
|
def reset
|
35
38
|
self.method = DEFAULT_METHOD
|
36
39
|
self.format = DEFAULT_FORMAT
|
37
|
-
self.
|
40
|
+
self.delivered = DEFAULT_DELIVERED
|
38
41
|
self.status_message = DEFAULT_STATUS_MESSAGE
|
39
42
|
self.headers = DEFAULT_HEADERS
|
43
|
+
self.authorized = DEFAULT_AUTHORIZED
|
40
44
|
end
|
41
45
|
|
42
46
|
def configure
|
data/lib/teachable/jg/version.rb
CHANGED
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.5
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|