birarda / logan

ruby gem to communicate with new Basecamp API
MIT License
16 stars 19 forks source link

Add comment to message #22

Open edporras opened 9 years ago

edporras commented 9 years ago

Hi, I'm in need of a way to post comments on existing messages and, unless I'm mistaken, it looks like this is not supported yet, right? Any chance you'd be able to add it soon?

If not, I'll try something similar to what was done for issue 6 but I wanted to check first.

Thank you

birarda commented 9 years ago

Assuming the API is the same as it was for 6 this should be pretty straight forward - I could put this up in a branch pretty quick if you wouldn't mind testing it from there? Unfortunately I don't use basecamp for work anymore so I don't have easy access to API.

birarda commented 9 years ago

I pushed the changes to a separate branch - message-comments.

The pre-release is here if you can test it out: https://github.com/birarda/logan/releases/tag/0.2.3

edporras commented 9 years ago

Wow, thanks so much. I'll give it a go and let you know.

edporras commented 9 years ago

Hi, sorry about the delay.

I tried your branch but I ended up modifying things a little bit because of my needs and I wanted to get your thoughts.

I imagine the "proper" way to go about this would be to load the project via the projects(proj_id) method, and then to load the message in a similar way. However, I don't think this is available either but I also think it's not necessary to make the call since I just need to post a comment to a message we already know the id for.

So, what I have temporarily done is, essentially, replicated your method within project like so:

module Logan
  class Project

….

   # post a comment to a message if the msg id is known                                                                                                                                                                   
    def create_message_comment(msg_id, content, subscribers = nil)
      body = { :content => content }
      body[:subscribers] = subscribers if subscribers != nil

      comment_params = {
        :body => body.to_json,
        :headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
      }

      response = Logan::Client.post "/projects/#{@id}/messages/#{msg_id}/comments.json", comment_params
      Logan::Comment.new response
    end

To be more correct, I should create an instance of Message on which I could make your call. I just want to avoid making a query to Basecamp to retrieve the message since it might not be necessary (unless the caller wants to query the list of recipients to update it).

I'm somewhat new to ruby so I'm not 100% certain but I think if I create an instance of Message, it's going to expect data as received from Basecamp whereas I'd like to have just a representation of the Message with the id. Does that make sense? Do you have some suggestions as to how I should rework this?

Alternatively, I could create a class method within Message that performs the action you wrote and that I replicated and then we could have both methods call it, if you feel this is valid usage.

I'm working on this in the evenings but I can reply if you have any questions or comments. Thank you.