justinweiss / reactive_resource

ActiveRecord-style associations and miscellaneous fixes for nested ActiveResources
http://rubydoc.info/gems/reactive_resource/frames
MIT License
53 stars 14 forks source link

Altering the extension #2

Closed rickthomasjr closed 13 years ago

rickthomasjr commented 13 years ago

One of my biggest gripes with ActiveResource is the inability to change the file extension of calls, particularly on custom method calls (AFAIK, the custom_method_url can't be overridden). Does this gem resolve that problem?

justinweiss commented 13 years ago

Are you trying to change the extension on a per-api basis, a per-resource basis, or a per-action basis? The first one is easy, the second one should be possible, and the third one would probably be a little tricky.

rickthomasjr commented 13 years ago

I am trying to change it on a per-API basis. On Mar 10, 2011 12:05 PM, "justinweiss" < reply@reply.github.com> wrote:

Are you trying to change the extension on a per-api basis, a per-resource basis, or a per-action basis? The first one is easy, the second one should be possible, and the third one would probably be a little tricky.

https://github.com/justinweiss/reactive_resource/issues/2#comment_856664

justinweiss commented 13 years ago

I think you should be able to handle that with ActiveResource using a custom format. Twilio, for instance, doesn't use extensions on their REST API so I had to do something similar: https://github.com/justinweiss/twilio_resource/blob/master/lib/twilio_resource/twilio_format.rb

Once you create a format, you can set it using something like self.format = :twilio inside your resource class. ActiveResource has a bug where not having an extension doesn't work (which ReactiveResource fixes), but other than that, you should be able to handle it with vanilla ActiveResource. You can still use ReactiveResource for the other features though :-) Does that help?

rickthomasjr commented 13 years ago

That is awesome stuff. Thanks.

On Thu, Mar 10, 2011 at 12:38 PM, justinweiss < reply@reply.github.com>wrote:

I think you should be able to handle that with ActiveResource using a custom format. Twilio, for instance, doesn't use extensions on their REST API so I had to do something similar: https://github.com/justinweiss/twilio_resource/blob/master/lib/twilio_resource/twilio_format.rb

Once you create a format, you can set it using something like self.format = :twilio inside your resource class. ActiveResource has a bug where not having an extension doesn't work (which ReactiveResource fixes), but other than that, you should be able to handle it with vanilla ActiveResource. You can still use ReactiveResource for the other features though :-) Does that help?

https://github.com/justinweiss/reactive_resource/issues/2#comment_856797

rickthomasjr commented 13 years ago

My employer's blog is ranked pretty well in Google - do you mind if I make a blog entry about this topic? I haven't seen this solution anywhere, so an entry could help a lot of folks.

On Thu, Mar 10, 2011 at 12:38 PM, justinweiss < reply@reply.github.com>wrote:

I think you should be able to handle that with ActiveResource using a custom format. Twilio, for instance, doesn't use extensions on their REST API so I had to do something similar: https://github.com/justinweiss/twilio_resource/blob/master/lib/twilio_resource/twilio_format.rb

Once you create a format, you can set it using something like self.format = :twilio inside your resource class. ActiveResource has a bug where not having an extension doesn't work (which ReactiveResource fixes), but other than that, you should be able to handle it with vanilla ActiveResource. You can still use ReactiveResource for the other features though :-) Does that help?

https://github.com/justinweiss/reactive_resource/issues/2#comment_856797

justinweiss commented 13 years ago

Yeah, definitely! It took some digging through the ActiveResource documentation and code to figure it out in the first place, so it would be nice to have it written down somewhere.

On Mar 10, 2011, at 11:22 AM, rickthomasjr wrote:

My employer's blog is ranked pretty well in Google - do you mind if I make a blog entry about this topic? I haven't seen this solution anywhere, so an entry could help a lot of folks.

On Thu, Mar 10, 2011 at 12:38 PM, justinweiss < reply@reply.github.com>wrote:

I think you should be able to handle that with ActiveResource using a custom format. Twilio, for instance, doesn't use extensions on their REST API so I had to do something similar: https://github.com/justinweiss/twilio_resource/blob/master/lib/twilio_resource/twilio_format.rb

Once you create a format, you can set it using something like self.format = :twilio inside your resource class. ActiveResource has a bug where not having an extension doesn't work (which ReactiveResource fixes), but other than that, you should be able to handle it with vanilla ActiveResource. You can still use ReactiveResource for the other features though :-) Does that help?

https://github.com/justinweiss/reactive_resource/issues/2#comment_856797

https://github.com/justinweiss/reactive_resource/issues/2#comment_857233

rickthomasjr commented 13 years ago

This should be out later this week. I'm linking to your reactive_resource github - is there another place you'd prefer I link to you as a reference?

Also, I have run into one more problem. I've slept since I fixed this problem in Active Resource, but my objects are being dasherized again now that I'm inheriting ReactiveResource. Are you aware of any way to prevent that from happening? (Dasherizing converts underscores to dashes in field names).

Thanks for all your assistance.

Rick Thomas

On Thu, Mar 10, 2011 at 2:38 PM, justinweiss < reply@reply.github.com>wrote:

Yeah, definitely! It took some digging through the ActiveResource documentation and code to figure it out in the first place, so it would be nice to have it written down somewhere.

On Mar 10, 2011, at 11:22 AM, rickthomasjr wrote:

My employer's blog is ranked pretty well in Google - do you mind if I make a blog entry about this topic? I haven't seen this solution anywhere, so an entry could help a lot of folks.

On Thu, Mar 10, 2011 at 12:38 PM, justinweiss < reply@reply.github.com>wrote:

I think you should be able to handle that with ActiveResource using a custom format. Twilio, for instance, doesn't use extensions on their REST API so I had to do something similar:

https://github.com/justinweiss/twilio_resource/blob/master/lib/twilio_resource/twilio_format.rb

Once you create a format, you can set it using something like self.format = :twilio inside your resource class. ActiveResource has a bug where not having an extension doesn't work (which ReactiveResource fixes), but other than that, you should be able to handle it with vanilla ActiveResource. You can still use ReactiveResource for the other features though :-) Does that help?

https://github.com/justinweiss/reactive_resource/issues/2#comment_856797

https://github.com/justinweiss/reactive_resource/issues/2#comment_857233

https://github.com/justinweiss/reactive_resource/issues/2#comment_857313

justinweiss commented 13 years ago

Cool! Linking to the github repo should be fine, I don't think I have any other place where I talk about the gem. As far as the dasherizing, I'm not totally sure -- I don't think ReactiveResource modifies that at all. You might be able to override the encode/decode functions in your custom format to un-dasherize or otherwise massage the data you're sending to or from the API.

On Mar 14, 2011, at 1:47 PM, rickthomasjr wrote:

This should be out later this week. I'm linking to your reactive_resource github - is there another place you'd prefer I link to you as a reference?

Also, I have run into one more problem. I've slept since I fixed this problem in Active Resource, but my objects are being dasherized again now that I'm inheriting ReactiveResource. Are you aware of any way to prevent that from happening? (Dasherizing converts underscores to dashes in field names).

Thanks for all your assistance.

Rick Thomas

On Thu, Mar 10, 2011 at 2:38 PM, justinweiss < reply@reply.github.com>wrote:

Yeah, definitely! It took some digging through the ActiveResource documentation and code to figure it out in the first place, so it would be nice to have it written down somewhere.

On Mar 10, 2011, at 11:22 AM, rickthomasjr wrote:

My employer's blog is ranked pretty well in Google - do you mind if I make a blog entry about this topic? I haven't seen this solution anywhere, so an entry could help a lot of folks.

On Thu, Mar 10, 2011 at 12:38 PM, justinweiss < reply@reply.github.com>wrote:

I think you should be able to handle that with ActiveResource using a custom format. Twilio, for instance, doesn't use extensions on their REST API so I had to do something similar:

https://github.com/justinweiss/twilio_resource/blob/master/lib/twilio_resource/twilio_format.rb

Once you create a format, you can set it using something like self.format = :twilio inside your resource class. ActiveResource has a bug where not having an extension doesn't work (which ReactiveResource fixes), but other than that, you should be able to handle it with vanilla ActiveResource. You can still use ReactiveResource for the other features though :-) Does that help?

https://github.com/justinweiss/reactive_resource/issues/2#comment_856797

https://github.com/justinweiss/reactive_resource/issues/2#comment_857233

https://github.com/justinweiss/reactive_resource/issues/2#comment_857313

Reply to this email directly or view it on GitHub: https://github.com/justinweiss/reactive_resource/issues/2#comment_872120