Class: SearchKit::Clients::Subscribers
- Inherits:
-
Object
- Object
- SearchKit::Clients::Subscribers
- Defined in:
- lib/search_kit/clients/subscribers.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #create(options = {}) ⇒ Object
- #info ⇒ Object
-
#initialize ⇒ Subscribers
constructor
A new instance of Subscribers.
- #update(options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Subscribers
Returns a new instance of Subscribers.
9 10 11 12 13 |
# File 'lib/search_kit/clients/subscribers.rb', line 9 def initialize uri = [ SearchKit.config.app_uri, "subscribers" ].join("/") @connection = Faraday.new(uri) @token = SearchKit.config.app_token end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
7 8 9 |
# File 'lib/search_kit/clients/subscribers.rb', line 7 def connection @connection end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
7 8 9 |
# File 'lib/search_kit/clients/subscribers.rb', line 7 def token @token end |
Instance Method Details
#create(options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/search_kit/clients/subscribers.rb', line 15 def create( = {}) = { data: { type: 'subscribers', attributes: } } response = connection.post("", ) body = JSON.parse(response.body, symbolize_names: true) fail Errors::BadRequest if response.status == 400 fail Errors::Unprocessable if response.status == 422 SearchKit::Models::Subscriber.new body.fetch(:data, {}) end |
#info ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/search_kit/clients/subscribers.rb', line 26 def info response = connection.get("", token: token) body = JSON.parse(response.body, symbolize_names: true) fail Errors::Unauthorized if response.status == 401 fail Errors::SubscriberNotFound if response.status == 404 SearchKit::Models::Subscriber.new body.fetch(:data, {}) end |
#update(options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/search_kit/clients/subscribers.rb', line 36 def update( = {}) = { token: token, data: { type: 'subscribers', attributes: } } response = connection.patch("", ) body = JSON.parse(response.body, symbolize_names: true) fail Errors::BadRequest if response.status == 400 fail Errors::Unauthorized if response.status == 401 fail Errors::SubscriberNotFound if response.status == 404 fail Errors::Unprocessable if response.status == 422 SearchKit::Models::Subscriber.new body.fetch(:data, {}) end |