controlshift / action-network-rest

Ruby client for interacting with the ActionNetwork REST API
MIT License
8 stars 4 forks source link

find_by_email method does not follow osdi encapsulation rules exactly #24

Open matthewbretherton opened 1 year ago

matthewbretherton commented 1 year ago

A request for an email with an apostrophe (') in it returned an error from Action Network

A lucky guess found that a two apostrophes ('') (as per mysql encapsulation) worked

Further reading on osdi found documentation that a single apostrophe in a search query needs to be escaped with another single apostrophe

My monkey patch

module ActionNetworkRest class People < Base def find_by_email(email)

This works for parsing exactly 1 person's info out of the response.

  # The response we get from Action Network is expected to have
  #
  # "_embedded": {
  #   "osdi:people": [{
  #       "identifiers": [
  #           "action_network:c947bcd0-929e-11e3-a2e9-12313d316c29"
  #            ....
  #        ]
  #    }]
  # }
  #
  osdi_encoded_string = email.gsub("'","''")
  url_encoded_filter_string = url_escape("email_address eq '#{osdi_encoded_string}'")
  response = client.get_request "#{base_path}?filter=#{url_encoded_filter_string}"
  person_object = response.body[:_embedded][osdi_key].first
  set_action_network_id_on_object(person_object) if person_object.present?
end

end end

lavaturtle commented 1 year ago

Wow, good catch! We'll see about fixing this. Thanks!

matthewbretherton commented 1 year ago

More lucky . . . went down a rabbit hole it was a mishandled sql issue until I read the oldie documentation

Which is kind of a compliment that the action network rest api gem is so good that I did not need to read the documentation

I also added some methods in people to get lists of signatures and tagging for a person - was pretty easy but suspect better to do using method missing and a list of such information sources ( which is provided in the people.list response )

I have a question as I am getting occasional strange response ( error responses ) from the signing of a petition

I know that signing fails is the address of the signing person is greater than 50 characters

Action Network support were not very helpful and the error message - you have uncovered an error and we are looking into it is also unhelpful

Just wondering if you have any ideas how / where why to go about solving this

PS - the API is neat - I should dig deeper to see how it hangs together

M

On 19 Jan 2023, at 12:50 am, Grey Moore @.***> wrote:

Wow, good catch! We'll see about fixing this. Thanks!

— Reply to this email directly, view it on GitHub https://github.com/controlshift/action-network-rest/issues/24#issuecomment-1387104807, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJIP2YDJWADQD7PEEHJOB3WS7YI7ANCNFSM6AAAAAAT6MUQ3Q. You are receiving this because you authored the thread.