instructure / pandarus

A Ruby library for the Canvas API (and code generator for other languages, eventually)
34 stars 25 forks source link

Demo code for passing in the hash options #5

Closed eriko closed 9 years ago

eriko commented 9 years ago

I am having issues passing in hashes to optional fields. Do you have an example?

client = Pandarus::Client.new( prefix: "https://#{hostname}/api", token: token) client_raw_terms = client.get_single_account(1) client_raw_terms = client.list_enrollment_terms(1, {workflow_state: 'all'}) NoMethodError: undefined method 'each_pair' for #<Array:0x007fbf5edd38d8>

canadaduane commented 9 years ago

It looks like you've bumped in to an issue with list_enrollment_terms--the docs say it returns an array of EnrollmentTerm options, but the API call actually returns a hash with a key enrollment_terms. For instance,

{"enrollment_terms"=>[{"end_at"=>nil, "id"=>31, "name"=>"Default Term", "start_at"=>nil, "workflow_state"=>"active", "sis_term_id"=>nil}]}

So, basically, you aren't doing anything wrong with the optional fields, it's that the docs aren't quite right, and Pandarus is just going by the docs.

eriko commented 9 years ago

Sweet. I am in the process of replacing the canvas-api gem with pandarus in the tool I built to convert our enrollment data into SIS packs and then to setup and monitor courses so I will want to get this working. When I run in to stuff like this I am thinking I can change the code documentation in a clone of the canvas docs and rebuild the gem? After that where can I report documentation errors?

I am assuming you are talking about the # @API List enrollment terms section of terms_api_controller.rb as where things are wrong.

canadaduane commented 9 years ago

Yes on all counts. You can report the documentation errors on canvas-lms and email me duane@instructure.com and I'll get them merged in as long as things don't change under our feet (we have a lot of doc changes coming through the pipeline right now) On Aug 26, 2014 6:18 PM, "Erik Ordway" notifications@github.com wrote:

Sweet. I am in the process of replacing the canvas-api gem with pandarus in the tool I built to convert our enrollment data into SIS packs and then to setup and monitor courses so I will want to get this working. When I run in to stuff like this I am thinking I can change the code documentation in a clone of the canvas docs and rebuild the gem? After that where can I report documentation errors?

I am assuming you are talking about the # @API List enrollment terms section of terms_api_controller.rb as where things are wrong.

— Reply to this email directly or view it on GitHub https://github.com/instructure/pandarus/issues/5#issuecomment-53511540.

eriko commented 9 years ago

So the only other instance that seems to use this pattern is NotificationPreference with for instance list_preferences_communication_channel_id and it experiences the same issue. render json: { notification_preferences: policies.map { |p| notification_policy_json(p, @current_user, session) } } render json: {enrollment_terms: enrollment_terms_json(terms, @current_user, session)} All the other examples of @API List return the json un wrapped. I was trying to find an example of a version Yard syntax that worked to base off of and this we it.

Any thoughts on what the documentation should look like for these methods?

canadaduane commented 9 years ago

I'm asking around, but so far I don't know of a way to document this type of return.

eriko commented 9 years ago

It look like an older way of doing ajax stuff so I wonder if it is something that was never cleaned up.

I can work around it for now by using canvas-api for getting the terms and keep marching on with pandarus for the rest as the parts I need seem to work fine.