Class: ShipitAPI::Commune
- Inherits:
-
Object
- Object
- ShipitAPI::Commune
- Defined in:
- lib/shipit_api/commune.rb
Class Method Summary collapse
Instance Method Summary collapse
- #all ⇒ Object
- #find(opts = {}) ⇒ Object
- #find_by_name(opts = {}) ⇒ Object
-
#initialize(opts = {}) ⇒ Commune
constructor
A new instance of Commune.
Constructor Details
#initialize(opts = {}) ⇒ Commune
Returns a new instance of Commune.
15 16 17 18 |
# File 'lib/shipit_api/commune.rb', line 15 def initialize(opts = {}) @opts = opts @api_call = ShipitAPI::Session.connection(self.class.name) end |
Class Method Details
.all(opts = {}) ⇒ Object
7 8 9 |
# File 'lib/shipit_api/commune.rb', line 7 def self.all(opts = {}) new(opts).all end |
.find(opts = {}) ⇒ Object
3 4 5 |
# File 'lib/shipit_api/commune.rb', line 3 def self.find(opts = {}) new().find(opts) end |
.find_by_name(opts = {}) ⇒ Object
11 12 13 |
# File 'lib/shipit_api/commune.rb', line 11 def self.find_by_name(opts = {}) new().find_by_name(opts) end |
Instance Method Details
#all ⇒ Object
20 21 22 23 |
# File 'lib/shipit_api/commune.rb', line 20 def all response = @api_call.get('', @opts) JSON.parse(response.body) end |
#find(opts = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/shipit_api/commune.rb', line 25 def find(opts = {}) opts = opts.empty? ? StandardError : opts response = @api_call.get("#{opts[:id]}") JSON.parse(response.body, symbolize_names: true) end |
#find_by_name(opts = {}) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/shipit_api/commune.rb', line 31 def find_by_name(opts = {}) opts = opts.empty? ? StandarError : opts commune = URI.encode(opts[:name]) response = @api_call.get("by_name/#{commune}") JSON.parse(response.body, symbolize_names: true) end |