Hey Dan,

Thanks for the input.  It has progressed quite a bit since I sent this
email, and I'm now in agreement that passing the session around when
creating new objects is ok.  The important part is keeping it out of the
public API.

Thanks again,
James

On Wed, Feb 10, 2010 at 11:23 PM, Dan Simpson <[email protected]> wrote:

> I don't see anything wrong with what you are doing.  You are abstracting
> the "annoying" aspect of dealing with the session away from the public API.
> The only other way would be storing it in a more global accessible variable
> or structure.
>
> If you really dislike setting the session everytime, you could set it as a
> class attribute accessor on the module Smirk
>
> module Smirk
>
>     class << self
>         attr_accessor :session_id
>     end
>
> end
>
> Then you can set Smirk::session_id = get(params,
> true)['Login']['Session']['id']
>
> That said, I think what you are doing is fine.
>
> --Dan
>
> On Tue, Feb 9, 2010 at 7:20 PM, James Miller <[email protected]>wrote:
>
>> Hi Everyone,
>>
>> I'm working on a gem that interacts with an API (smugmug.com, if you
>> care) and I'm running into an issue.
>>
>> The API requires that you make an initial request with a username and
>> password to receive a session_id.  Subsequent requests just use the
>> session_id.  Fine, no big deal:
>>
>> > smug = Smirk::Client.new("username", "password")
>> > smug.session_id
>> => "my_valid_session_id"
>> > smug.albums.map(&:title).join(", ")
>> => "Trees, Mountains, Yada Yada"
>>
>> albums is a method on the Client class that grabs all albums in that
>> account and instantiates each as an Album object -- session_id is an ivar in
>> Client, so no problem there.  If I want to make any additional API calls
>> from within the Album class, I need that session_id.  Is the best (or only)
>> way to initialize an Album object with the session_id?  It's equally
>> annoying when I want all images within an Album, as I need to pass that
>> session id over to the new Image objects as well.
>>
>> Relevant files are here if you want to see where it's at now:
>> http://github.com/bensie/smirk/blob/master/lib/smirk/client.rb
>> http://github.com/bensie/smirk/blob/master/lib/smirk/album.rb
>> http://github.com/bensie/smirk/blob/master/lib/smirk/image.rb
>>
>> Thanks everyone,
>>
>> James
>>
>> --
>> SD Ruby mailing list
>> [email protected]
>> http://groups.google.com/group/sdruby
>
>
>  --
> SD Ruby mailing list
> [email protected]
> http://groups.google.com/group/sdruby

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to