Class: RocketPants::Client
- Inherits:
-
APISmith::Base
- Object
- APISmith::Base
- RocketPants::Client
- Defined in:
- lib/rocket_pants/client.rb
Overview
Implements a generalised base for building clients on top of the rocket pants controller. This automatically unpacks the API into the correct response types, handles errors (using the same error registry as the server) and in general makes it simpler to implement api clients.
Class Method Summary collapse
- ._original_endpoint ⇒ Object
-
.endpoint(path) ⇒ Object
Sets the endpoint url, taking into account the version number as a prefix if present.
- .version(number = nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
Initializes a new client, optionally setting up the host for this client.
Constructor Details
#initialize(options = {}) ⇒ Client
Initializes a new client, optionally setting up the host for this client.
68 69 70 71 72 73 74 |
# File 'lib/rocket_pants/client.rb', line 68 def initialize( = {}) super # Setup the base uri if passed in to the client. if [:api_host].present? :base_uri => HTTParty.normalize_base_uri([:api_host]) end end |
Class Method Details
._original_endpoint ⇒ Object
54 |
# File 'lib/rocket_pants/client.rb', line 54 alias _original_endpoint endpoint |
.endpoint(path) ⇒ Object
Sets the endpoint url, taking into account the version number as a prefix if present.
58 59 60 61 |
# File 'lib/rocket_pants/client.rb', line 58 def endpoint(path) self._actual_endpoint = path _original_endpoint File.join(*[_version, path].compact.map(&:to_s)) end |
.version ⇒ Integer .version(number) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/rocket_pants/client.rb', line 44 def version(number = nil) if number.nil? _version else self._version = number endpoint _actual_endpoint number end end |