{"action":"created","issue":{"url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/154","repository_url":"https://api.github.com/repos/ga-wdi-boston/capstone-project","labels_url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/154/labels{/name}","comments_url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/154/comments","events_url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/154/events","html_url":"https://github.com/ga-wdi-boston/capstone-project/issues/154","id":158592643,"number":154,"title":"3rd Party API request. Having trouble figuring out how to parse response data and store locally.","user":{"login":"louarnos","id":17519351,"avatar_url":"https://avatars.githubusercontent.com/u/17519351?v=3","gravatar_id":"","url":"https://api.github.com/users/louarnos","html_url":"https://github.com/louarnos","followers_url":"https://api.github.com/users/louarnos/followers","following_url":"https://api.github.com/users/louarnos/following{/other_user}","gists_url":"https://api.github.com/users/louarnos/gists{/gist_id}","starred_url":"https://api.github.com/users/louarnos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/louarnos/subscriptions","organizations_url":"https://api.github.com/users/louarnos/orgs","repos_url":"https://api.github.com/users/louarnos/repos","events_url":"https://api.github.com/users/louarnos/events{/privacy}","received_events_url":"https://api.github.com/users/louarnos/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2016-06-06T02:58:24Z","updated_at":"2016-06-06T18:51:13Z","closed_at":null,"body":"I currently have my backend set so that a post request to route '/eventful' will fire a request to a 3rd party API. I have managed to get be able to get this data to save as a single entry in the data store on the front end. My issue is that this data comes back as an array of events. \r\n\r\nBecause this data is not present in my database prior to a user sending requesting it from the api, a model hook does not have anything to work with on page load and throws an error (or so it seems to me);\r\n\r\nI've been trying to figure out how to take the single entry (the array of events) and to create new records with it so that I can then render them. Here is my code to store the single entry:\r\n\r\nMy eventful Route:\r\n\r\n``` bash \r\nimport Ember from 'ember';\r\n\r\nexport default Ember.Route.extend({\r\n  // model () {\r\n  //   return this.get('store').find('eventful');\r\n  // },\r\n\r\n  data : {},\r\n\r\n  ajax: Ember.inject.service(),\r\n\r\n  actions: {\r\n    searchForEvents (data) {\r\n      let eventful = this.get('store').createRecord('eventful', data);\r\n      return eventful.save();\r\n      // return this.get('store').findAll('eventful');\r\n      // let something = this.get('store').findAll('eventful');\r\n      // console.log('something:', something);\r\n      // return eventful.save();\r\n    }\r\n  }\r\n});\r\n```\r\nMy eventful adapter:\r\n\r\n``` bash\r\nimport ApplicationAdapter from 'ga-wdi-boston.event-bookmarker/application/adapter';\r\nimport Ember from 'ember';\r\n\r\nexport default ApplicationAdapter.extend({\r\n  ajax: Ember.inject.service(),\r\n  createRecord (store, type, record) {\r\n  let serialized = this.serialize(record, { includeId: true});\r\n  let data = { serialized };\r\n  return this.get('ajax').request('/eventful', {\r\n    method: 'POST',\r\n    data: data,\r\n  });\r\n  // .then((events) => {\r\n  //   // console.log(events);\r\n  //   events.eventful[0].event.forEach(function (concert){\r\n  //     // console.log(concert);\r\n  //     return concert;\r\n  //     // let eventfulConcert = this.get('store').createRecord('eventful-event', concert);\r\n  //     // return eventfulConcert.save();\r\n  //     });\r\n  //   });\r\n  }\r\n});\r\n```\r\n\r\nMy eventful Model:\r\n\r\n``` bash\r\nimport DS from 'ember-data';\r\n\r\nexport default DS.Model.extend({\r\n  event: DS.attr('string'),\r\n});\r\n```\r\n\r\nAs you can see in the lines commented out in my adapter, I have tried to do a forEach on the array that is returned from the request to the 3rd party api and then save each individual event as a different model. I get an error when i do this that says: \r\n\r\n``` \r\nrest.js:390 Uncaught TypeError: this.ajax is not a functionfindAll @ rest.js:390_findAll @ finders.js:136_fetchAll @ store.js:909findAll @ store.js:881searchForEvents @ route.js:17triggerEvent @ ember.debug.js:28580trigger @ ember.debug.js:53473Router.trigger @ ember.debug.js:52232_emberRuntimeSystemObject.default.extend.send @ ember.debug.js:28045_emberMetalMixin.Mixin.create.send @ ember.debug.js:32723_emberMetalMixin.Mixin.create.triggerAction @ ember.debug.js:36297_emberViewsViewsView.default.extend.sendAction @ ember.debug.js:41731searchForEvents @ component.js:6_emberViewsViewsView.default.extend.send @ ember.debug.js:41747superWrapper @ ember.debug.js:23110runRegisteredAction @ ember.debug.js:29633Backburner.run @ ember.debug.js:678run @ ember.debug.js:21139actions.push.handler @ ember.debug.js:29627(anonymous function) @ ember.debug.js:44705jQuery.event.dispatch @ jquery.js:4737elemData.handle @ jquery.js:4549\r\n```\r\n\r\n\r\nI have done some research, and it seems I may have to define different DS.attr() to handle arrays. My backend has two different embed schemas in users (events and followees) so I'm going to have to learn to handle storing data as arrays in the ember store. \r\n"},"comment":{"url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/comments/224052164","html_url":"https://github.com/ga-wdi-boston/capstone-project/issues/154#issuecomment-224052164","issue_url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/154","id":224052164,"user":{"login":"louarnos","id":17519351,"avatar_url":"https://avatars.githubusercontent.com/u/17519351?v=3","gravatar_id":"","url":"https://api.github.com/users/louarnos","html_url":"https://github.com/louarnos","followers_url":"https://api.github.com/users/louarnos/followers","following_url":"https://api.github.com/users/louarnos/following{/other_user}","gists_url":"https://api.github.com/users/louarnos/gists{/gist_id}","starred_url":"https://api.github.com/users/louarnos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/louarnos/subscriptions","organizations_url":"https://api.github.com/users/louarnos/orgs","repos_url":"https://api.github.com/users/louarnos/repos","events_url":"https://api.github.com/users/louarnos/events{/privacy}","received_events_url":"https://api.github.com/users/louarnos/received_events","type":"User","site_admin":false},"created_at":"2016-06-06T18:51:12Z","updated_at":"2016-06-06T18:51:12Z","body":"I guess I'm confused at what you mean exactly @gaand. My the request returns an array of concert information, and i need to get it to the frontend. So the payload is an array, even if I strip down to just the keys I need. \r\n\r\n@J-Weeks Is that a DS.attr() type? I'm looking for a way to model the data coming from the API. "}}
{"actor":{"display_login":"louarnos"}}