whichdigital / active-rest-client

ActiveRestClient API Client
https://rubygems.org/gems/active_rest_client
MIT License
386 stars 44 forks source link

Support 'has_one' relationship #82

Closed nathanhoel closed 9 years ago

nathanhoel commented 9 years ago

Allows you to recursively support single association relationship types.

If you have JSON like

{
  "name": "Jeff"
  "address": {
    "street": "123 Fredrick St.",
    "city": "Metropolis",
  }
}

and classes like this

class Address < ActiveRestClient::Base
  def full_string
    return "#{self.street}, #{self.city}, #{self.region}, #{self.country}"
  end
end

class Person < ActiveRestClient::Base
  get :find, "/people/:id", :has_one => {:address => Address}
end

It will instantiate the address class instead of the Person class and you can then call things like

puts @person.address.full_string

If there is anything I can do to help get this merged I'd love to work with you guys on doing that, thanks!

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-0.18%) to 98.99% when pulling 544a384f1a25296b4041dc9c21f893e271fa1898 on nathanhoel:has-one-association into ea0a7af1ec848e21a92e126f53a2071e1427a5b0 on whichdigital:master.

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-0.18%) to 98.99% when pulling 544a384f1a25296b4041dc9c21f893e271fa1898 on nathanhoel:has-one-association into ea0a7af1ec848e21a92e126f53a2071e1427a5b0 on whichdigital:master.

nathanhoel commented 9 years ago

Forgot to check specs again, will do then let you know

coveralls commented 9 years ago

Coverage Status

Coverage increased (+0.01%) to 99.18% when pulling fc56ec40e52633d17dc7383c537fb18789e6d50f on nathanhoel:has-one-association into ea0a7af1ec848e21a92e126f53a2071e1427a5b0 on whichdigital:master.

coveralls commented 9 years ago

Coverage Status

Coverage increased (+0.01%) to 99.18% when pulling fc56ec40e52633d17dc7383c537fb18789e6d50f on nathanhoel:has-one-association into ea0a7af1ec848e21a92e126f53a2071e1427a5b0 on whichdigital:master.

andyjeffries commented 9 years ago

Nice work @nathanhoel, thank you!