teachable-stats 0.1.0 → 0.1.1

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: 578241224c44c9e3e01e17badc09053f9c5f8fc7
4
- data.tar.gz: cbcb16f4c2d68132c5391fd9c71082ea59ca737c
3
+ metadata.gz: a3b55698b6091bd707a99a8976b5164b7595248b
4
+ data.tar.gz: a7d40aded414bda94d5000f21cf84e257a26fea8
5
5
  SHA512:
6
- metadata.gz: 9ffa51e559741b39bbdc20547c16556f41f626d291d9c0a3c5c52704b549db8873c3f013d3fd3e480eaaf184d0d6f58b9ad551dc960579b5c03f1cf829ad6184
7
- data.tar.gz: a1b90057a89c02de11be38ff5e3409cc725a9e0b788748872e9a3dc16904758b0abc5c4b6d08538dfb661787c57dba5376fef6cb7fea9d9b6b741c87da6c9338
6
+ metadata.gz: edda8af6eda05f91cbe56257d3c1ff70f6656cbef1b7cb106d769a8d0806d41a84c3e64f53ef62670fb96a45722aec5a4baee7fbe801811c6212f22689487521
7
+ data.tar.gz: 39bd256bd10b145fc31902f652dd5f8d71b318b1f7e9b1e2a372e6c6d03abc63aba3b18d888b8d3e183462dcb3fe6a9ca5abc3d45b7b43dbd54ba55b7811c98f
data/README.md CHANGED
@@ -24,7 +24,14 @@ Or install it yourself as:
24
24
 
25
25
  ## Usage
26
26
 
27
+ On a high-level, this is how we will use the API:
28
+
29
+ 1. Register for the API
30
+ 2. Authenticate/Configure the gem for API use.
31
+ 3. Make API calls using the #get_user, #get_orders, #create_my_order, #destroy_my_order methods.
32
+
27
33
  **Registering to the API**
34
+
28
35
  In order to use the gem, you first need to register an account with Teachable. You used to have to make a complicated post request directly to Teachable's API via this complicated curl request:
29
36
 
30
37
  ```bash
@@ -40,6 +47,7 @@ Teachable::Stats.register(email: "new_email@example.com", password: "8LettersLon
40
47
  Note the password field has to be at least 8 letters long and the email address cannot already exist in the database.
41
48
 
42
49
  **Getting user_token and credentials**
50
+
43
51
  If you are an already registered user and simply want your credentials sent back to you, you can simply get your credentials via this .get_token convenience method
44
52
 
45
53
  ```ruby
@@ -62,32 +70,33 @@ That will return your credentials, including your token, in this form:
62
70
  Note the returned value of the .get_token method is a ruby hash and it does not show your password. However, it does have your user_token which you need to use to configure your gem.
63
71
 
64
72
  **Configuring your gem**
73
+
65
74
  You need to set your :user_email and :user_token prior to making API requests to the Teachable API. Configuring your gem simply means providing the gem your registered user email and user_token. There are two ways to do this:
66
75
 
67
76
  1. In your application, you can write this code to manually configure your gem:
68
77
 
69
- ```ruby
70
- Teachable::Stats.configuration do |config|
71
- config.user_email = "your_email@example.com"
72
- config.user_token = "some_secure_random_string_goes_here_that_you_can_get_via_the_get_token_method"
73
- end
74
- ```
78
+ ```ruby
79
+ Teachable::Stats.configuration do |config|
80
+ config.user_email = "your_email@example.com"
81
+ config.user_token = "some_secure_random_string_goes_here_that_you_can_get_via_the_get_token_method"
82
+ end
83
+ ```
75
84
 
76
- Again, the user_email and user_token can be obtained via the .get_token method provided by the gem.
85
+ Again, the user_email and user_token can be obtained via the .get_token method provided by the gem.
77
86
 
78
- 2. You can also configure your gem using the gem's .authenticate convenience method. This is how you can use the convenience method.
87
+ 2. Instead of calling .get_token and manually configuring the gem within your application, you can also configure your gem using the gem's .authenticate convenience method. This is how you can use the convenience method.
79
88
 
80
- ```ruby
81
- Teachable::Stats.authenticate(email: "valid_email1@example.com", password: "password")
82
- ```
89
+ ```ruby
90
+ Teachable::Stats.authenticate(email: "valid_email1@example.com", password: "password")
91
+ ```
83
92
 
84
- Give that above method a try! That email and password are valid. You should see something like this return:
93
+ Give that above method a try! That email and password are valid. You should see something like this return:
85
94
 
86
- ```
87
- "Logged in as user: valid_email1@example.com with token: -y9s9TyMHdWmniBLfE8i"
88
- ```
95
+ ```
96
+ "Logged in as user: valid_email1@example.com with token: -y9s9TyMHdWmniBLfE8i"
97
+ ```
89
98
 
90
- Behind the scenes, that sets the class variables called user_email and user_token to the email and user_token that are shown in the string. All you need to provide to the authenticate convenience method are your already registered and valid email and password. That's it!
99
+ (This doesn't actually truly authenticate with the API... it really just sets the class variables user_email and user_token so that they can be sent along with the API requests in query parameters.) Behind the scenes, that sets the class variables called user_email and user_token to the email and user_token that are shown in the string. All you need to provide to the authenticate convenience method are your already registered and valid email and password. That's it!
91
100
 
92
101
  ## Making queries to the Teachable API
93
102
 
@@ -105,12 +114,12 @@ Let's see how to make requests to all 4!
105
114
  Teachable::Stats.get_user
106
115
  ```
107
116
 
108
- **Orders*get**
117
+ **Orders#get**
109
118
  ```ruby
110
119
  Teachable::Stats.get_orders
111
120
  ```
112
121
 
113
- **Orders*post**
122
+ **Orders#post**
114
123
  ```ruby
115
124
  Teachable::Stats.create_my_order(number: 1, total: 2.0, total_quantity: 3, email: "valid_email1@example.com")
116
125
  ```
@@ -119,6 +128,7 @@ In the above convenience method for creating_orders, you currently need to provi
119
128
 
120
129
  The above method will create an order for the authenticated user. See this:
121
130
 
131
+ **Orders#destroy**
122
132
  ```ruby
123
133
  Teachable::Stats.destroy_my_order(order_id: 2)
124
134
  ```
@@ -280,7 +290,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
280
290
 
281
291
  ## Contributing
282
292
 
283
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/teachable-stats.
293
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Jwan622/teachable_challenge_gem
284
294
 
285
295
  Many thanks to the development team:
286
296
  - Jeffrey Wan
@@ -1,4 +1,3 @@
1
-
2
1
  module Configuration
3
2
  def configuration
4
3
  yield self
@@ -0,0 +1,13 @@
1
+ module CustomErrors
2
+ class AuthenticationError < StandardError
3
+ def initialize(msg="You need to call #authenticate first and pass in your email and password. For example: Teachable::Stats.authenticate(email: 'YourEmail@example.com', password: 'password')")
4
+ super
5
+ end
6
+ end
7
+
8
+ class RegistrationError < StandardError
9
+ def initialize(msg="That username and password combination is incorrect. I think you need to register first.")
10
+ super
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Teachable
2
2
  module Stats
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{This is a wrapper for the mock Teachable API}
13
13
  spec.description = %q{The teachable-stats gem is a wrapper for the Teachable API. Hopefully this saves you time!}
14
- spec.homepage = "https://github.com/Jwan622/teachable_challenge_gem/blob/master/lib/teachable/stats.rb"
14
+ spec.homepage = "https://github.com/Jwan622/teachable_challenge_gem"
15
15
 
16
16
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
17
  # delete this section to allow pushing this gem to any host.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teachable-stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey Wan
@@ -139,6 +139,7 @@ files:
139
139
  - bin/console
140
140
  - bin/setup
141
141
  - lib/helpers/configuration.rb
142
+ - lib/helpers/custom_errors.rb
142
143
  - lib/teachable/stats.rb
143
144
  - lib/teachable/stats/authenticate.rb
144
145
  - lib/teachable/stats/get_token.rb
@@ -150,7 +151,7 @@ files:
150
151
  - lib/teachable/stats/version.rb
151
152
  - notes.md
152
153
  - teachable-stats.gemspec
153
- homepage: https://github.com/Jwan622/teachable_challenge_gem/blob/master/lib/teachable/stats.rb
154
+ homepage: https://github.com/Jwan622/teachable_challenge_gem
154
155
  licenses: []
155
156
  metadata: {}
156
157
  post_install_message:
@@ -174,3 +175,4 @@ signing_key:
174
175
  specification_version: 4
175
176
  summary: This is a wrapper for the mock Teachable API
176
177
  test_files: []
178
+ has_rdoc: