discourse_api 0.19.0 → 0.20.0

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: 83abc19a3d7e268f4e7bbed2ba58af029149bf8f
4
- data.tar.gz: a355175ab4498a2d02f2cbb340b48987770882ba
3
+ metadata.gz: f274e6981e46cd2e393462cb9df4f24c8933aa5a
4
+ data.tar.gz: de4fded436009054fd23e9b889a3437ae6350452
5
5
  SHA512:
6
- metadata.gz: 5db56a7d1101b1568cd51e52dee5df79651697c11f84c83e9b5c4e7c73336689e34a8e0ea1e6eb72f082c6efb6e61056b2ce5ac6c732acb355aff6a9044c0781
7
- data.tar.gz: 98317ae29f5fc092f5126f988d35c73e29eb46baab5264fab7dd7e96fa6b73b643dd558121d5ef003736a2dd7c2d2beba22e0e3e5cf88c976a75b78cb760f1a5
6
+ metadata.gz: 255799bc16658b2c84945ba46e349126a095590dd869d2b715a58dc2a03e3a3cf4e008764b2e8fab29c3d544301391a77068f5a84ff433fa69ffceffec2a51ab
7
+ data.tar.gz: 61d1bb2ce5287e6666be41546948477a9baad9a122d14d004ed12156bd6d22aa967bace0160b9d31b0ccdda5463dbd0ac548c81f9761704b8336e8f24d099395
@@ -2,6 +2,12 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [0.20.0] - 2017-12-13
6
+ ### Added
7
+ - Add base error class
8
+ ### Fixed
9
+ - Update SSO
10
+
5
11
  ## [0.19.0] - 2017-11-22
6
12
  ### Added
7
13
  - Added optional `create_post` params
data/README.md CHANGED
@@ -80,4 +80,5 @@ client.create_private_message( #=> Creates a private messages b
80
80
  1. Install discourse locally
81
81
  2. Inside of your discourse directory, run: `bundle exec rake db:api_test_seed`
82
82
  3. Start discourse: `bundle exec rails s`
83
- 4. Inside of your discourse_api directory, run: `bundle exec rspec spec/`
83
+ 4. Install bundler in the discourse_api directory, run `gem install bundler`
84
+ 5. Inside of your discourse_api directory, run: `bundle exec rspec spec/`
@@ -1,5 +1,8 @@
1
1
  module DiscourseApi
2
- class Error < StandardError
2
+ class DiscourseError < StandardError
3
+ end
4
+
5
+ class Error < DiscourseError
3
6
  attr_reader :wrapped_exception
4
7
 
5
8
  # Initializes a new Error object
@@ -12,15 +15,15 @@ module DiscourseApi
12
15
  end
13
16
  end
14
17
 
15
- class UnauthenticatedError < StandardError
18
+ class UnauthenticatedError < DiscourseError
16
19
  end
17
20
 
18
- class NotFoundError < StandardError
21
+ class NotFoundError < DiscourseError
19
22
  end
20
23
 
21
- class UnprocessableEntity < StandardError
24
+ class UnprocessableEntity < DiscourseError
22
25
  end
23
26
 
24
- class TooManyRequests < StandardError
27
+ class TooManyRequests < DiscourseError
25
28
  end
26
29
  end
@@ -4,14 +4,16 @@ require 'openssl'
4
4
 
5
5
  module DiscourseApi
6
6
  class SingleSignOn
7
- ACCESSORS = [:nonce, :name, :username, :email, :avatar_url, :avatar_force_update,
8
- :about_me, :external_id, :return_sso_url, :admin, :moderator, :suppress_welcome_message, :title]
7
+ ACCESSORS = [:nonce, :name, :username, :email, :avatar_url, :avatar_force_update, :require_activation,
8
+ :bio, :external_id, :return_sso_url, :admin, :moderator, :suppress_welcome_message, :title,
9
+ :add_groups, :remove_groups, :groups]
9
10
  FIXNUMS = []
10
- BOOLS = [:avatar_force_update, :admin, :moderator, :suppress_welcome_message]
11
+ BOOLS = [:avatar_force_update, :admin, :moderator, :require_activation, :suppress_welcome_message]
12
+ ARRAYS = [:groups]
11
13
  #NONCE_EXPIRY_TIME = 10.minutes # minutes is a rails method and is causing an error. Is this needed in the api?
12
14
 
13
15
  attr_accessor(*ACCESSORS)
14
- attr_accessor :sso_secret, :sso_url
16
+ attr_writer :sso_secret, :sso_url
15
17
 
16
18
  def self.sso_secret
17
19
  raise RuntimeError, "sso_secret not implemented on class, be sure to set it on instance"
@@ -44,15 +46,12 @@ module DiscourseApi
44
46
  if BOOLS.include? k
45
47
  val = ["true", "false"].include?(val) ? val == "true" : nil
46
48
  end
49
+ val = Array(val) if ARRAYS.include?(k) && !val.nil?
47
50
  sso.send("#{k}=", val)
48
51
  end
49
52
 
50
- decoded_hash.each do |k,v|
51
- # 1234567
52
- # custom.
53
- #
54
- if k[0..6] == "custom."
55
- field = k[7..-1]
53
+ decoded_hash.each do |k, v|
54
+ if field = k[/^custom\.(.+)$/, 1]
56
55
  sso.custom_fields[field] = v
57
56
  end
58
57
  end
@@ -60,6 +59,10 @@ module DiscourseApi
60
59
  sso
61
60
  end
62
61
 
62
+ def diagnostics
63
+ DiscourseApi::SingleSignOn::ACCESSORS.map { |a| "#{a}: #{send(a)}" }.join("\n")
64
+ end
65
+
63
66
  def sso_secret
64
67
  @sso_secret || self.class.sso_secret
65
68
  end
@@ -72,32 +75,30 @@ module DiscourseApi
72
75
  @custom_fields ||= {}
73
76
  end
74
77
 
75
-
76
78
  def sign(payload)
77
79
  OpenSSL::HMAC.hexdigest("sha256", sso_secret, payload)
78
80
  end
79
81
 
80
-
81
- def to_url(base_url=nil)
82
+ def to_url(base_url = nil)
82
83
  base = "#{base_url || sso_url}"
83
84
  "#{base}#{base.include?('?') ? '&' : '?'}#{payload}"
84
85
  end
85
86
 
86
87
  def payload
87
- payload = Base64.encode64(unsigned_payload)
88
+ payload = Base64.strict_encode64(unsigned_payload)
88
89
  "sso=#{CGI::escape(payload)}&sig=#{sign(payload)}"
89
90
  end
90
91
 
91
92
  def unsigned_payload
92
93
  payload = {}
93
- ACCESSORS.each do |k|
94
- next if (val = send k) == nil
95
94
 
95
+ ACCESSORS.each do |k|
96
+ next if (val = send k) == nil
96
97
  payload[k] = val
97
98
  end
98
99
 
99
100
  if @custom_fields
100
- @custom_fields.each do |k,v|
101
+ @custom_fields.each do |k, v|
101
102
  payload["custom.#{k}"] = v.to_s
102
103
  end
103
104
  end
@@ -1,3 +1,3 @@
1
1
  module DiscourseApi
2
- VERSION = "0.19.0"
2
+ VERSION = "0.20.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discourse_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.0
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-11-22 00:00:00.000000000 Z
14
+ date: 2017-12-13 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: faraday
@@ -307,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
307
307
  version: '0'
308
308
  requirements: []
309
309
  rubyforge_project:
310
- rubygems_version: 2.5.1
310
+ rubygems_version: 2.6.8
311
311
  signing_key:
312
312
  specification_version: 4
313
313
  summary: Allows access to the Discourse API