teachable-jg 0.0.6 → 0.0.7

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: 9723db89952fca603ae20865254d748b1ea15ce6
4
- data.tar.gz: 4e677735ec3ecd70ca734bb2625e9eab001681ce
3
+ metadata.gz: b55d53eb7337f0328b6c546f393b8684dff2b1b5
4
+ data.tar.gz: 17c1acb03205d97fef71f5c7021117e525db8ac6
5
5
  SHA512:
6
- metadata.gz: dae902b0c020301bfa3fc7aadd7c9fbaf522ce72997a20763a6596a3d8e5c64a063d07ee78639dc1bf5570d074dd8a654f9993ecbfbbbe37d4d54da331ffccf0
7
- data.tar.gz: 45a96a2b32e19074cdc36141028a9bc7f77e77ad0f262abc14cd7df123a83b856b73fee7d884e20d07371c262dab86eab88976229a3c6f0911b78aa0cdf964b5
6
+ metadata.gz: aedaa12e7e9f4285a14a4434993f2ec34c0af9701ea6dee5ada129d0c8a8c7717226791961081a1b711ea3447bfb8b7eab4dc8a0727f586d9f0aab5bbcd781db
7
+ data.tar.gz: d91111406d0e15e676bc442764d1e342e1744872f26ae22bbcdbf943021f29ce45f86fd8fb8bfc9ddf76752f83fe592212cb6d9d633e6adae2d2d4cc3ecf6cb3
@@ -34,9 +34,9 @@ module Teachable
34
34
  path = endpoint + build_path(options[:registration])
35
35
 
36
36
  query = {user: {
37
- "email" => options[:email],
38
- "password" => options[:password],
39
- "password_confirmation" => options[:password_confirmation]
37
+ "email" => options[:email],
38
+ "password" => options[:password],
39
+ "password_confirmation" => options[:password_confirmation]
40
40
  }}
41
41
 
42
42
  resp = HTTParty.post(
@@ -47,17 +47,23 @@ module Teachable
47
47
  end
48
48
 
49
49
  def confirm_status(options={})
50
- resp = post_to_users_endpoint(options)
50
+ if has_required_attributes?(options, :email, :password)
51
51
 
52
- if resp.code == 200
53
- body = process_body(resp.body)
52
+ resp = post_to_users_endpoint(options)
54
53
 
55
- self.delivered = true if body["success"]
56
- self.authorized = true if body["login"] == "verified"
54
+ if resp.code == 200
55
+ body = process_body(resp.body)
57
56
 
58
- return body
57
+ self.delivered = true if body["success"]
58
+ self.authorized = true if body["login"] == "verified"
59
+
60
+ return body
61
+ else
62
+ return resp.code
63
+ end
59
64
  else
60
- return resp.code
65
+ self.delivered = false
66
+ {"success"=>false, "user_info"=>"missing or invalid params"}
61
67
  end
62
68
  end
63
69
 
@@ -94,8 +100,8 @@ module Teachable
94
100
 
95
101
  def user_info(options={})
96
102
  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?
103
+ path = Teachable::Jg::Configuration::CURRENT_USER_ENDPOINT
104
+ if has_required_attributes?(options, :user_email, :user_token)
99
105
  resp = get_user_info(path, options)
100
106
  else
101
107
  self.delivered = false
@@ -132,12 +138,37 @@ module Teachable
132
138
  end
133
139
  end
134
140
 
141
+ def destroy_orders(path, options)
142
+ path_with_params = path + "/#{options[:order_id]}?user_email=#{options[:user_email]}&user_token=#{options[:user_token]}"
143
+
144
+ resp = HTTParty.delete(
145
+ path_with_params,
146
+ headers: headers
147
+ )
148
+
149
+ if resp.code == 200
150
+ body = process_body(resp.body)
151
+ self.delivered = true if body["success"]
152
+ return body
153
+ else
154
+ return resp.code
155
+ end
156
+ end
157
+
158
+ def has_required_attributes?(options, *attributes)
159
+ attributes << :password_confirmation if options[:registration]
160
+
161
+ return false if attributes.detect do |attr|
162
+ !(options.has_key?(attr) && !options[attr].nil?)
163
+ end
164
+
165
+ true
166
+ end
167
+
135
168
  def create_order(options)
136
169
  if authorized
137
- path = options[:path] || Teachable::Jg::Configuration::ORDERS_ENDPOINT
138
- if options[:total] && !options[:total].nil? &&
139
- options[:total_quantity] && !options[:total_quantity].nil? &&
140
- options[:email] && !options[:email].nil?
170
+ path = Teachable::Jg::Configuration::ORDERS_ENDPOINT
171
+ if has_required_attributes?(options, :total, :total_quantity, :email, :user_email, :user_token)
141
172
  resp = post_to_orders(path, options)
142
173
  else
143
174
  self.delivered = false
@@ -147,7 +178,21 @@ module Teachable
147
178
  self.delivered = false
148
179
  {"success"=>false, "login"=>"failed to authorize"}
149
180
  end
181
+ end
150
182
 
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
192
+ else
193
+ self.delivered = false
194
+ {"success"=>false, "login"=>"failed to authorize"}
195
+ end
151
196
  end
152
197
 
153
198
  end # Client
@@ -6,19 +6,20 @@ module Teachable
6
6
 
7
7
  VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
8
8
 
9
- DEFAULT_ENDPOINT = 'http://secure.localhost.com:3000/users'
9
+ DEFAULT_ENDPOINT = "http://secure.localhost.com:3000/users"
10
10
  CURRENT_USER_ENDPOINT = "http://secure.localhost.com:3000/api/users/current_user/edit"
11
11
  ORDERS_ENDPOINT = "http://secure.localhost.com:3000/api/orders"
12
12
 
13
+ DEFAULT_HEADERS = { "Content-Type" => "application/json",
14
+ "Accept" => "application/json" }
13
15
  DEFAULT_METHOD = :post
14
- DEFAULT_USER_AGENT = "Teachable API Ruby Gem #{Teachable::Jg::VERSION}".freeze
15
16
  DEFAULT_FORMAT = :json
17
+
18
+ DEFAULT_USER_AGENT = "Teachable Mock API Ruby Gem #{Teachable::Jg::VERSION}".freeze
16
19
  DEFAULT_DELIVERED = false
17
20
  DEFAULT_AUTHORIZED = false
18
- DEFAULT_HEADERS = { "Content-Type" => "application/json",
19
- "Accept" => "application/json" }
20
- DEFAULT_STATUS_MESSAGE = ""
21
21
 
22
+ DEFAULT_STATUS_MESSAGE = ""
22
23
 
23
24
  # Build accessor methods for every config options so we can do this, for example:
24
25
  # Teachable::Jg.format = :xml
@@ -37,11 +38,11 @@ module Teachable
37
38
  end
38
39
 
39
40
  def reset
41
+ self.headers = DEFAULT_HEADERS
40
42
  self.method = DEFAULT_METHOD
41
43
  self.format = DEFAULT_FORMAT
42
44
  self.delivered = DEFAULT_DELIVERED
43
45
  self.status_message = DEFAULT_STATUS_MESSAGE
44
- self.headers = DEFAULT_HEADERS
45
46
  self.authorized = DEFAULT_AUTHORIZED
46
47
  end
47
48
 
@@ -1,5 +1,5 @@
1
1
  module Teachable
2
2
  module Jg
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project:
150
- rubygems_version: 2.4.8
150
+ rubygems_version: 2.6.12
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: A convenient wrapper for the valid endpoints of Teachable Mock API