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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33bf7cfe21698b5ec9baeb4cc3ec1fb895618c2c
4
- data.tar.gz: 227a08f4bdd94d817afd4bdda72bc610878a6140
3
+ metadata.gz: 2b9eb0e5665cab09e9030363f7b209beb16571e4
4
+ data.tar.gz: 5bbbdd2a1d1ab0aab270b1ec6c6f43c3456b3b63
5
5
  SHA512:
6
- metadata.gz: b09825669942c6a671e1b7e963884f32ff9b63cc3ce1b23b6bec50e3a8160ac92f297acb5450a9a987042988ecfd0c444e615f3b37265e5b7728e6a2202cefcb
7
- data.tar.gz: 950ffa896e1f287b129e5cfb630e31ae1414bc0d3136c9e2ea928158726fa7f0cc2f492877496462c15567895eddf9a297cc009f2f24a83a936307ddde3d21d5
6
+ metadata.gz: a94f0abfa77f3d80d94ad79332e48941438b6119bcc6b1e82a66a858bc2d4ca470b4c9d70733b23dc704037610a54750a17e6145b734cad59915cacf2e0ec38c
7
+ data.tar.gz: 73e14225826732136131abc1eb3bd400f4566cce3ef258e0bcedf9abce8ddfb3b18f4ea6ea0f916406b22ef6a28853092ca3a24e45d76a35f424f0946a95f369
data/Rakefile CHANGED
@@ -1 +1,11 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
2
+
3
+ task :console do
4
+ require 'irb'
5
+ require 'irb/completion'
6
+ require 'teachable/jg' # You know what to do.
7
+ require "pry"
8
+ Pry.start
9
+ ARGV.clear
10
+ # IRB.start
11
+ end
data/bin/console CHANGED
@@ -10,5 +10,5 @@ require "teachable/jg"
10
10
  require "pry"
11
11
  Pry.start
12
12
 
13
- require "irb"
14
- IRB.start
13
+ # require "irb"
14
+ # IRB.start
@@ -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
- # Define the same set of accessors as the Teachable module
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
- def initialize(_options={})
12
- self.class.basic_auth(account_id, account_token)
13
- end
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 = [:endpoint, :user_agent, :method].freeze
5
- VALID_OPTIONS_KEYS = [:api_key, :format].freeze
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
- DEFAULT_ENDPOINT = 'http://teachable.dev/api'
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
- DEFAULT_API_KEY = nil
13
- DEFAULT_FORMAT = :json
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 { |key| [key, send(key)] }.flatten ]
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.endpoint = DEFAULT_ENDPOINT
30
- self.method = DEFAULT_METHOD
31
- self.user_agent = DEFAULT_USER_AGENT
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
@@ -1,5 +1,5 @@
1
1
  module Teachable
2
2
  module Jg
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
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.2
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-12 00:00:00.000000000 Z
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