teachable-jg 0.0.7 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b55d53eb7337f0328b6c546f393b8684dff2b1b5
4
- data.tar.gz: 17c1acb03205d97fef71f5c7021117e525db8ac6
3
+ metadata.gz: 29d8d3f15328104db4000097d9bfebff00600613
4
+ data.tar.gz: b99aed86e82f6bd9d4e489ca020f1c5507f79c63
5
5
  SHA512:
6
- metadata.gz: aedaa12e7e9f4285a14a4434993f2ec34c0af9701ea6dee5ada129d0c8a8c7717226791961081a1b711ea3447bfb8b7eab4dc8a0727f586d9f0aab5bbcd781db
7
- data.tar.gz: d91111406d0e15e676bc442764d1e342e1744872f26ae22bbcdbf943021f29ce45f86fd8fb8bfc9ddf76752f83fe592212cb6d9d633e6adae2d2d4cc3ecf6cb3
6
+ metadata.gz: a11bbf225aac8d6071058eb598d715e0bcb5b16cae03d32512f5620cd637ce12fc8a011881c655cede573528b5452121e12e1e2afa40fe2724b3a69b601df0de
7
+ data.tar.gz: 42edca275df3d2f7bf5f2b51662d65488731b82e9cc3fb25ef6f49f4463ead0f55bc816c2a2bbe84b3faea858cb8e7cc840c856c4fa1a6b0d7ddaaf1d2532867
@@ -7,14 +7,9 @@ module Teachable
7
7
 
8
8
  format :json
9
9
 
10
- # SUCCESSFUL_LOGIN = {"success"=>true, "login"=>"verified"}
11
- # SUCCESSFUL_REGISTRATION = {"success"=>true, "registration"=>"verified"}
12
-
13
- # Define the same set of accessors as the Teachable module
14
10
  attr_accessor *Teachable::Jg::Configuration::VALID_CONFIG_KEYS
15
11
  attr_accessor :endpoint, :authorized
16
12
 
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
13
  def initialize(options={})
19
14
  merged_options = Teachable::Jg.options.merge(options)
20
15
 
@@ -26,56 +21,22 @@ module Teachable
26
21
  @status_message = confirm_status(options)
27
22
  end
28
23
 
29
- def build_path(registration)
30
- registration ? "/register" : "/sign-in"
31
- end
32
-
33
- def post_to_users_endpoint(options)
34
- path = endpoint + build_path(options[:registration])
35
-
36
- query = {user: {
37
- "email" => options[:email],
38
- "password" => options[:password],
39
- "password_confirmation" => options[:password_confirmation]
40
- }}
41
-
42
- resp = HTTParty.post(
43
- path,
44
- query: query,
45
- headers: headers
46
- )
47
- end
48
-
49
- def confirm_status(options={})
50
- if has_required_attributes?(options, :email, :password)
51
-
52
- resp = post_to_users_endpoint(options)
53
-
54
- if resp.code == 200
55
- body = process_body(resp.body)
56
-
57
- self.delivered = true if body["success"]
58
- self.authorized = true if body["login"] == "verified"
59
-
60
- return body
24
+ def user_info(options={})
25
+ if authorized
26
+ path = Teachable::Jg::Configuration::CURRENT_USER_ENDPOINT
27
+ if has_required_attributes?(options, :user_email, :user_token)
28
+ resp = get(path, options)
61
29
  else
62
- return resp.code
30
+ self.delivered = false
31
+ {"success"=>false, "user_info"=>"missing or invalid params"}
63
32
  end
64
33
  else
65
34
  self.delivered = false
66
- {"success"=>false, "user_info"=>"missing or invalid params"}
67
- end
68
- end
69
-
70
- def process_body(body)
71
- if body.is_a?(String)
72
- JSON.parse(body)
73
- else
74
- {"success"=>false, "login"=>"no json response"}
35
+ {"success"=>false, "login"=>"failed to authorize"}
75
36
  end
76
37
  end
77
38
 
78
- def get_user_info(path, options)
39
+ def get(path, options)
79
40
  user_headers = headers.reject {|key| key == "Accept" }
80
41
 
81
42
  query = {
@@ -98,14 +59,60 @@ module Teachable
98
59
  end
99
60
  end
100
61
 
101
- def user_info(options={})
62
+ def post_to_users(options)
63
+ path = endpoint + build_path(options[:registration])
64
+
65
+ query = {user: {
66
+ "email" => options[:email],
67
+ "password" => options[:password],
68
+ "password_confirmation" => options[:password_confirmation]
69
+ }}
70
+
71
+ resp = HTTParty.post(
72
+ path,
73
+ query: query,
74
+ headers: headers
75
+ )
76
+ end
77
+
78
+ def create_order(options)
102
79
  if authorized
103
- path = Teachable::Jg::Configuration::CURRENT_USER_ENDPOINT
80
+ path = Teachable::Jg::Configuration::ORDERS_ENDPOINT
81
+ if has_required_attributes?(options, :total, :total_quantity, :email, :user_email, :user_token)
82
+ resp = post_to_orders(path, options)
83
+ else
84
+ self.delivered = false
85
+ {"success"=>false, "create_order"=>"missing or invalid params"}
86
+ end
87
+ else
88
+ self.delivered = false
89
+ {"success"=>false, "login"=>"failed to authorize"}
90
+ end
91
+ end
92
+
93
+ def orders(options)
94
+ if authorized
95
+ path = Teachable::Jg::Configuration::ORDERS_ENDPOINT
104
96
  if has_required_attributes?(options, :user_email, :user_token)
105
- resp = get_user_info(path, options)
97
+ resp = get(path, options)
106
98
  else
107
99
  self.delivered = false
108
- {"success"=>false, "user_info"=>"missing or invalid params"}
100
+ {"success"=>false, "get_orders"=>"missing or invalid params"}
101
+ end
102
+ else
103
+ self.delivered = false
104
+ {"success"=>false, "login"=>"failed to authorize"}
105
+ end
106
+ end
107
+
108
+ def delete_order(options)
109
+ if authorized
110
+ path = Teachable::Jg::Configuration::ORDERS_ENDPOINT
111
+ if has_required_attributes?(options, :order_id, :user_email, :user_token)
112
+ resp = destroy_order(path, options)
113
+ else
114
+ self.delivered = false
115
+ {"success"=>false, "delete_order"=>"missing or invalid params"}
109
116
  end
110
117
  else
111
118
  self.delivered = false
@@ -138,7 +145,7 @@ module Teachable
138
145
  end
139
146
  end
140
147
 
141
- def destroy_orders(path, options)
148
+ def destroy_order(path, options)
142
149
  path_with_params = path + "/#{options[:order_id]}?user_email=#{options[:user_email]}&user_token=#{options[:user_token]}"
143
150
 
144
151
  resp = HTTParty.delete(
@@ -155,46 +162,48 @@ module Teachable
155
162
  end
156
163
  end
157
164
 
158
- def has_required_attributes?(options, *attributes)
159
- attributes << :password_confirmation if options[:registration]
165
+ def build_path(registration)
166
+ registration ? "/register" : "/sign-in"
167
+ end
160
168
 
161
- return false if attributes.detect do |attr|
162
- !(options.has_key?(attr) && !options[attr].nil?)
163
- end
169
+ def confirm_status(options={})
170
+ if has_required_attributes?(options, :email, :password)
164
171
 
165
- true
166
- end
172
+ resp = post_to_users(options)
167
173
 
168
- def create_order(options)
169
- if authorized
170
- path = Teachable::Jg::Configuration::ORDERS_ENDPOINT
171
- if has_required_attributes?(options, :total, :total_quantity, :email, :user_email, :user_token)
172
- resp = post_to_orders(path, options)
174
+ if resp.code == 200
175
+ body = process_body(resp.body)
176
+
177
+ self.delivered = true if body["success"]
178
+ self.authorized = true if body["login"] == "verified"
179
+
180
+ return body
173
181
  else
174
- self.delivered = false
175
- {"success"=>false, "create_order"=>"missing or invalid params"}
182
+ return resp.code
176
183
  end
177
184
  else
178
185
  self.delivered = false
179
- {"success"=>false, "login"=>"failed to authorize"}
186
+ {"success"=>false, "user_info"=>"missing or invalid params"}
180
187
  end
181
188
  end
182
189
 
183
- def delete_order(options)
184
- if authorized
185
- path = Teachable::Jg::Configuration::ORDERS_ENDPOINT
186
- if has_required_attributes?(options, :order_id, :user_email, :user_token)
187
- resp = destroy_orders(path, options)
188
- else
189
- self.delivered = false
190
- {"success"=>false, "delete_order"=>"missing or invalid params"}
191
- end
190
+ def process_body(body)
191
+ if body.is_a?(String)
192
+ JSON.parse(body)
192
193
  else
193
- self.delivered = false
194
- {"success"=>false, "login"=>"failed to authorize"}
194
+ {"success"=>false, "login"=>"no json response"}
195
195
  end
196
196
  end
197
197
 
198
+ def has_required_attributes?(options, *attributes)
199
+ attributes << :password_confirmation if options[:registration]
200
+
201
+ return false if attributes.detect do |attr|
202
+ !(options.has_key?(attr) && !options[attr].nil?)
203
+ end
204
+
205
+ true
206
+ end
198
207
  end # Client
199
208
  end
200
209
  end
@@ -1,5 +1,5 @@
1
1
  module Teachable
2
2
  module Jg
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
data/teachable-jg.gemspec CHANGED
@@ -11,15 +11,17 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{A convenient wrapper for the valid endpoints of Teachable Mock API}
13
13
  spec.description = %q{A convenient wrapper for the valid endpoints of Teachable Mock API}
14
- spec.homepage = "https://www.cnn.com" # place holder for now
14
+ spec.homepage = "https://github.com/zioplox11/teachable-jg" # place holder for now
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
17
  spec.bindir = "exe"
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
+
20
21
  # if spec.respond_to?(:metadata)
21
- # spec.metadata['allowed_push_host'] = "https://mygemserver.com" # place holder for now
22
+ # spec.metadata['allowed_push_host'] = "https://mygemserver.com" # commenting out for now
22
23
  # end
24
+
23
25
  spec.add_development_dependency "bundler", "~> 1.9"
24
26
  spec.add_development_dependency "rake", "~> 12.0"
25
27
  spec.add_development_dependency "pry"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teachable-jg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua
@@ -128,7 +128,7 @@ files:
128
128
  - lib/teachable/jg/configuration.rb
129
129
  - lib/teachable/jg/version.rb
130
130
  - teachable-jg.gemspec
131
- homepage: https://www.cnn.com
131
+ homepage: https://github.com/zioplox11/teachable-jg
132
132
  licenses: []
133
133
  metadata: {}
134
134
  post_install_message: