Module: Tatooine::Resource::ClassMethods
- Defined in:
- lib/tatooine/resource.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #count ⇒ Object
- #get(id) ⇒ Object
- #list(opts = {}) ⇒ Object
- #next ⇒ Object
- #previous ⇒ Object
- #schema ⇒ Object
Instance Method Details
#connection ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/tatooine/resource.rb', line 82 def connection = { :headers => { "User-Agent" => "Tatooine Ruby Gem - #{Tatooine::VERSION}" }, :url => "#{Tatooine::API_BASE}#{@resource_path}/" } @connection ||= Faraday.new() do |faraday| faraday.response :raise_http_error faraday.response :dates faraday.response :json faraday.adapter Faraday.default_adapter end end |
#count ⇒ Object
60 61 62 |
# File 'lib/tatooine/resource.rb', line 60 def count @count || get_count end |
#get(id) ⇒ Object
72 73 74 75 76 |
# File 'lib/tatooine/resource.rb', line 72 def get(id) load_schema result = connection.get("#{id}/") new(result.body) end |
#list(opts = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/tatooine/resource.rb', line 50 def list(opts={}) load_schema url = opts.delete("url") || "" body = connection.get(url, opts).body @count = body["count"] @next = body["next"] @previous = body["previous"] body["results"].map { |result| new(result) } end |
#next ⇒ Object
64 65 66 |
# File 'lib/tatooine/resource.rb', line 64 def next list "url" => @next if @next end |
#previous ⇒ Object
68 69 70 |
# File 'lib/tatooine/resource.rb', line 68 def previous list "url" => @previous if @previous end |
#schema ⇒ Object
78 79 80 |
# File 'lib/tatooine/resource.rb', line 78 def schema load_schema end |