Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Handle extra API attributes with a warning. #5

Merged
merged 1 commit into from almost 3 years ago

3 participants

Caius Durling Emmanuel Oga Will Jessop
Caius Durling
caius commented May 03, 2011

Rather than die with a NoMethodError, just #warn about trying to set a non-existent attribute instead.

Caius Durling Handle extra API attributes with a warning.
Rather than die with a NoMethodError, just #warn about trying to set a non-existent attribute instead.
9e17a9c
Emmanuel Oga
Owner

Hi there. Not sure why are you doing that. Where are those extra API parameters coming from? Are you trying to add your own attributes to the objects, or are you getting extra parameters from campfire (i.e., is any of the firering classes outdated?)

Caius Durling
caius commented May 04, 2011

They've added an extra attribute to the user json (avatar_url), which currently causes firering to crash out with a NoMethodError for avatar_url=. Idea of this commit is to stop firering crashing in the time between new attributes being added and firering being updated. Coding defensively when something that will change beyond your control is a good thing in my opinion.

Will Jessop
wjessop commented May 04, 2011

EmmanuelOga, check out the API docs http://developer.37signals.com/campfire/users.

https://github.com/EmmanuelOga/firering/blob/master/lib/firering/instantiator.rb#L12-15 is broken because it makes assumptions about the format of the data we return, and we added a field.

Emmanuel Oga
Owner

Being defensive is important, as it is being correct. That's why I was asking what was the underlying cause of you wanting to add that code. Looks good to me, I'll add it and change a little bit the wording. I'll change it too to use the built in logger.

Emmanuel Oga EmmanuelOga merged commit 0bd3b3f into from May 04, 2011
Emmanuel Oga EmmanuelOga closed this May 04, 2011
Emmanuel Oga
Owner

btw, just released this together with the avatar_url fix as 1.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 03, 2011
Caius Durling Handle extra API attributes with a warning.
Rather than die with a NoMethodError, just #warn about trying to set a non-existent attribute instead.
9e17a9c
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 6 additions and 1 deletion. Show diff stats Hide diff stats

  1. 7  lib/firering/instantiator.rb
7  lib/firering/instantiator.rb
@@ -10,8 +10,13 @@ def instantiate(conn, data, base_key = nil, &callback)
10 10
       attributes ||= Hash.new
11 11
 
12 12
       attributes.each do |key, val|
  13
+        setter = "#{key}="
13 14
         value = ( key.to_s =~ /(_at|_on)$/ ) ? (Time.parse(val) rescue val) : val
14  
-        instance.send("#{key}=", value)
  15
+        if instance.respond_to?(setter)
  16
+          instance.send(setter, value)
  17
+        else
  18
+          Kernel.warn "WARNING: Tried to set #{setter} #{value.inspect} on a #{instance.class} instance but it didn't respond"
  19
+        end
15 20
       end
16 21
 
17 22
       callback.call(instance) if callback
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.