hackgvl / OpenData

Open data projects, including real-time and reusable data for local tech meetups, events, and map layers.
16 stars 3 forks source link

Drupal and REST #15

Closed KCulture closed 9 years ago

KCulture commented 9 years ago

Wanted to know how Drupal setup was going?

allella commented 9 years ago

Nothing yet on the Drupal side.

KCulture commented 9 years ago

Does the group have an IRC channel or something?

allella commented 9 years ago

@smoking-peanuts Landon, I'm going to setup a Drupal 8 site and start playing with building a REST API with the organization data.

It would help if if you want to pick up on what we talked about in late Oct, https://github.com/codeforgreenville/UpstateEvents/wiki/Meeting-Notes-2014.10.28#next-steps and gather keys Evitebrite, Facebook, etc based on which site each organization uses to post their events.

KCulture commented 9 years ago

Hey

I am a little confused on how I go about getting key's.  Is this the token that will allow us to interact with sever?Are we just looking for the key type? Help is appreciated. -landon

 On Saturday, December 27, 2014 2:03 PM, Jim Ciallella <notifications@github.com> wrote:

@smoking-peanuts Landon, I'm going to setup a Drupal 8 site and start playing with building a REST API with the organization data.It would help if if you want to pick up on what we talked about in late Oct, https://github.com/codeforgreenville/UpstateEvents/wiki/Meeting-Notes-2014.10.28#next-steps and gather keys Evitebrite, Facebook, etc based on which site each organization uses to post their events.— Reply to this email directly or view it on GitHub.

allella commented 9 years ago

It depends on where each community posts their events.

For instance, UpstatePHP uses Eventbrite. So, if you find their organization profile on Eventbrite it has a URL of http://www.eventbrite.com/o/upstatephp-6881540935 Where the 6881540935 is the organization key that would be needed to search for events belonging to that org.

There is a new column in the spreadsheet. The immediate goal is to figure out what each organization's key value is and paste it into that column. You can see the real example I just filled out for UpstatePHP. You can start by filling in the other 2 or 3 organizations that have Eventbrite listed in the spreadsheet. Even if they have no active events, or old events like RestFest, you can still get the key.

Eventbrite's documentation doesn't say where to find the organization ID, but I just figured that's it from experience.

http://developer.eventbrite.com/doc/organizers/ and I confirmed it's correct by using the organization ID to get a list of events for UpstatePHP http://developer.eventbrite.com/doc/organizers/organizer_list_events/ like http://www.eventbrite.com/rss/organizer_list_events/6881540935

allella commented 9 years ago

To determine the Meetup group's ID value you must log into Meetup and then go to their "console" tool for the group lookup functionality. https://secure.meetup.com/meetup_api/console/?path=/2/groups

Then, you need to paste in a community's Meetup.com URL name into the group_urlname text box.

For example, Code for Greenville's Meetup.com page is http://www.meetup.com/Upstate-Code-for-America/ so, I pasted Upstate-Code-for-America into the group_urlname textbox and then hit Enter.

It will now show a "Response" and in there the first value that says "id" (below utc_offset) is the group_id. That's the value we want to add to our spreadsheet.

So, in this case, I got "id": 14215742, so I added 14215742 to the spreadsheet to indicate that is Code for Greenville's group_id

Meetup.com Group Documentation http://www.meetup.com/meetup_api/docs/2/groups/

allella commented 9 years ago

@smoking-peanuts We probably won't use RSS, but here are notes on it. https://github.com/codeforgreenville/UpstateEvents/issues/16

KCulture commented 9 years ago

@allella So how is the Rest API going.. anything that I can do to help?

allella commented 9 years ago

@smoking-peanuts I got the basic schema setup in Drupal 8. I tried to import all 35 records, but the Feeds module has some bugs.

I'll see if I can import it in. If not then I may need a hand with data entry.

allella commented 9 years ago

@smoking-peanuts The feeds module is "not stable". I'm going to try to create records using the REST API to see how that works.

https://www.drupal.org/node/2022803

allella commented 9 years ago

@smoking-peanuts

Alright, the REST API is up and working.

Drupal 8 is still a bit buggy and incomplete, so I spent about 3 hours trying to deal with Drupal 8 instability and 30 minutes to actually configure things and figure how to add an update a record. I actually had to reinstall Drupal, so the work I did last night setting up the Organization fields is gone, but that's only about 5-10 minutes of work.

Anyway, I was able to create (POST) a test organization with a Name (aka title) and a status (aka field_situation) and then update the title using a (PATCH).

This means I'll be able to programmatically POST all 35 organizations, so no need to type them in.

Viewing the Organization

Again, there's only two fields on the organization at the moment, but I'll add them soon.

Here's the human readable web page. https://data.openupstate.org/node/2

You'll need to install the Dev HTTP Client plugin for Chrome to see the REST response for the organization. I know that may not make sense, but if you go to the "Using the REST API" section of https://drupalize.me/blog/201401/introduction-restful-web-services-drupal-8 then he has screen shots and it's rather easy.

Other Notes

The update command in REST is usually PUT, but Drupal is using PATCH instead because of technical reasons which are way over my head. So, GET, POST, PATCH, DELETE are the 4 commands that correspond to view, add, update, delete.

It's currently necessary to use Content-Type: application/hal+json for POST and PATCH due to the issues I described here https://www.drupal.org/node/1964034#comment-9619331

allella commented 9 years ago

Doing a Simple REST GET Method

So, once the Postman Client plugin is installed in Google Chrome](https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en) you can just fill in the values shown in the screenshot. However, I'll have to give you the full username and password.

Request URL https://data.openupstate.org/node/7?_format=json OR, it's alias https://data.openupstate.org/organization/code-for-greenville?_format=json

Note: Drupal 8 changed things and now requires a _format at the end of GET requests, which is stupid, as using an Accept: header is the better way to do such things for a REST API. Still, Accept: application/json

PHP_AUTH_USER: rest-read-only PHP_AUTH_PW: {ask allella and he will share}

and then just hit "Send".

Note, this screenshot shows another Chrome Plugin, not Postman, but the general idea is the same. rest-api-organization-get-example

This should yield a 200 OK response, along with a JSON object response with organization and Drupal data, which is the machine parse-able version of the organization data. And, that's the point of this first step of the API.

1) humans and their web browsers can GET https://data.openupstate.org/node/1 and see an organization web page 2) machines can add, update, delete, and download organizations through the REST standard by using the same URL https://data.openupstate.org/node/1

Example of the data from a GET

{
    "nid": [
        {
            "value": "1"
        }
    ],
    "uuid": [
        {
            "value": "4e6c3292-a8f0-4b6e-a30f-15a0d8589877"
        }
    ],
    "vid": [
        {
            "value": "1"
        }
    ],
    "type": [
        {
            "target_id": "organization"
        }
    ],
    "langcode": [
        {
            "value": "en"
        }
    ],
    "title": [
        {
            "value": "Code For Greenville 2"
        }
    ],
    "uid": [
        {
            "target_id": "2"
        }
    ],
    "status": [
        {
            "value": "1"
        }
    ],
    "created": [
        {
            "value": "1423793426"
        }
    ],
    "changed": [
        {
            "value": "1423806628"
        }
    ],
    "promote": [
        {
            "value": "0"
        }
    ],
    "sticky": [
        {
            "value": "0"
        }
    ],
    "revision_timestamp": [
        {
            "value": "1423793454"
        }
    ],
    "revision_uid": [
        {
            "target_id": "2"
        }
    ],
    "revision_log": [
        {
            "value": ""
        }
    ],
    "path": [
        {
            "alias": null,
            "pid": null
        }
    ],
    "field_situation": [
        {
            "value": "active"
        }
    ]
}
KCulture commented 9 years ago

Hey Jim, I didn't read all of your e-mail but I will get to it Sunday and start seeing how I can participate.. Thanks so much for getting drupal and the REST api setup..-landon

 On Friday, February 13, 2015 1:27 AM, Jim Ciallella <notifications@github.com> wrote:

Helpful Tutorials (Tuts) and Documentation http://tntfoss-vivekvpandya.rhcloud.com/node/40 https://drupalize.me/blog/201401/introduction-restful-web-services-drupal-8 http://build2be.com/content/state-rest-headless-drupal-8 https://www.drupal.org/node/2098511 JSON Validation Tool http://pro.jsonlint.com/ Jim Summarizing the State of Drupal 8 PATCH https://www.drupal.org/node/1964034#comment-9619331— Reply to this email directly or view it on GitHub.