Closed mvsoliveira closed 6 years ago
Hi Marcos,
Not difficult at all. As you can tell this is very much a work in progress...I hadn't needed Services yet for the project I was working on, so I hadn't gotten around to adding the endpoint. :-)
I can probably get this done pretty quickly now that I know there's some interest. Check back in a couple of days, or I'll gladly accept a pull request.
Thanks! Bill
I’m working on adding the services endpoint. Almost done. Need to test.
@billdeitrick Your framework is so awesome I was able to add all the other endpoints. Pull requests are available. Thank you for creating this project!
Hello @pastorhudson, thanks a lot for adding the new endpoints. I checked them out from your repository and tried to use the services endpoint. I tested two class members: songs and arrangements. the first works but the second not.
I get the following error:
Traceback (most recent call last): File "C:/Users/msilvaol/PycharmProjects/PCOSongs/pcosongs.py", line 11, in <module> for arrangement in pco.services.arrangements.list(): File "C:\Users\msilvaol\PycharmProjects\PCOSongs\pypco\endpoints\base_endpoint.py", line 257, in list_by_url response = self.dispatch_single_request(url, params=query_params) File "C:\Users\msilvaol\PycharmProjects\PCOSongs\pypco\endpoints\base_endpoint.py", line 126, in dispatch_single_request response.raise_for_status() File "C:\Python37\lib\site-packages\requests\models.py", line 939, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.planningcenteronline.com/services/v2/arrangements
The url https://api.planningcenteronline.com/services/v2/arrangements indeed does not exist. While the https://api.planningcenteronline.com/services/v2/songs exists.
The arrangement seems to be a member of each song: Clicking in the "self" link: Clicking in the "arrangements" link:
So at this point I am able to access the lyrics/chords of each song, which actually i am interested.
Can you have a look on it? Is it easy to fix?
I am adding here a discussion with KingsGate Community Church in UK. They would like to see a continuation of the open source PCO projector. maybe one of you could give your opinion from our discussion. If one or both of you would be interested in proposing a solution, you could even propose a quote to them. they are looking for a company which would upgrade it to the v2 of the API, or redesign it in a new technology.
@mvsoliveira This is because the arrangement endpoint is accessed as a relation from the song endpoint. Notice the URL from the API docs for getting a single arrangement:
https://api.planningcenteronline.com/services/v2/songs/1/arrangements/1
Try something like:
song = pco.services.songs.get(123) # < Use a song ID applicable to your account here
for arrangement in song.rel.arrangements.list():
print(arrangement)
There are more examples in the docstring for the RelationWrapper class here: https://github.com/billdeitrick/pypco/blob/master/pypco/models/base_model.py
I haven't looked at the code from @pastorhudson yet, but that's how it should work.
@pastorhudson -- great work, thank you! I'm hoping to get some time to roll your pull requests in over the weekend.
I've been debating about making the client completely auto-discovering before a real "release"; this way it wouldn't need to be changed when changes are made to the PCO API. However, I do like having the endpoint and model classes, as this means things like autocompletion/intellisense work nicely.
Now that I know there's some interest in this library, I'll work on getting some better documentation up. My goal is to have this on PyPi to make installation trivial.
Hello @billdeitrick thanks a lot for explaining this.
I managed to do it this way:
In case there is anything not ideal, please let me know.
Concerning the auto-discovering/endpoint and model classes. Maybe you could have both if the endpoint and model classes would be automatically generated, right? they release any documentation when changes happens? Or one could write a script that could scan the API and check for modifications in the data structure and generate the models automatically?
I am a hardware engineer (a bit new with the kind of things you are doing here), but we have some mechanisms of generating C++ classes automatically in verification software.
@mvsoliveira That's exactly how services endpoint works. Glad you got it sorted.
As for the api discovery. It really wasn't too hard to add the endpoints. From what I've seen PCO doesn't change the api that often.
@mvsoliveira You got it. As you can tell, I didn't test my example. Fixed it for posterity, though. :-)
I like the idea of auto generation. The API doesn't change that much, as @pastorhudson said, but I'd like as little effort to be required to keep up with API changes as possible. I'd rather put in more effort up front if it means less manual maintenance in the long run. PCO does post about changes in a Slack channel, that's probably the most reliable place I'm aware of to see updates.
PR from @pastorhudson for Services has now been rolled into the master branch. Planning to pull in the rest of the endpoints he has committed as soon as time permits.
Regarding auto endpoint discovery, for now I'm going to roll with the current declarative format, and revisit moving to auto discovery in the future. My goals for this project at this point are as follows:
Any help with these items would be quite welcome! :-)
Hello, how hard would be to have a model for the Services API?
Thanks a lot for writing this package.
Cheers.
Marcos