Class: Smartsend::Client
- Inherits:
-
Object
- Object
- Smartsend::Client
- Defined in:
- lib/smartsend/client.rb
Defined Under Namespace
Classes: Response
Constant Summary collapse
- @@logging =
false
Class Method Summary collapse
Instance Method Summary collapse
- #get(path) ⇒ Object
- #get_plain(path) ⇒ Object
-
#initialize(account = nil) ⇒ Client
constructor
A new instance of Client.
- #post(path, params) ⇒ Object
- #request ⇒ Object
Constructor Details
Class Method Details
.with_logs ⇒ Object
7 8 9 10 11 |
# File 'lib/smartsend/client.rb', line 7 def self.with_logs @@logging = true yield @@logging = false end |
Instance Method Details
#get(path) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/smartsend/client.rb', line 26 def get(path) log("GET #{path}") request do http.get(url(path)) end end |
#get_plain(path) ⇒ Object
34 35 36 |
# File 'lib/smartsend/client.rb', line 34 def get_plain(path) http.get(url(path)) end |
#post(path, params) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/smartsend/client.rb', line 17 def post(path, params) log("POST #{path}") log(params) request do http.post(url(path), json: params) end end |
#request ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/smartsend/client.rb', line 38 def request response = yield log(response) log(response.body.to_s) case response.code when (200..299) Response.new(JSON.parse(response)).successful!(response.code) when 401 raise Smartsend::AuthorizationError, 'Unable to authorize' when 404 raise Smartsend::NotFoundError, 'Resource not found' else Response.new(JSON.parse(response)).failed!(response.code) end end |