UNPKG

aping-plugin-bandsintown

Version:
8 lines 6.3 kB
/** @name: aping-plugin-bandsintown @version: 0.7.8 (28-01-2016) @author: Jonathan Hornung <jonathan.hornung@gmail.com> @url: https://github.com/JohnnyTheTank/apiNG-plugin-bandsintown @license: MIT */ "use strict";angular.module("jtt_aping_bandsintown",["jtt_bandsintown"]).directive("apingBandsintown",["apingBandsintownHelper","apingUtilityHelper","bandsintownFactory",function(a,b,c){return{require:"?aping",restrict:"A",replace:"false",link:function(d,e,f,g){var h=g.getAppSettings(),i=b.parseJsonFromAttributes(f.apingBandsintown,a.getThisPlattformString(),h);i.forEach(function(d){var e={model:h.model,showAvatar:d.showAvatar||!1,artist:d.artist||void 0};"undefined"!=typeof d.items?e.items=d.items:e.items=h.items,"undefined"!=typeof h.getNativeData?e.getNativeData=h.getNativeData:e.getNativeData=!1;var f={app_id:b.getApiCredentials(a.getThisPlattformString(),"app_id")||"apiNG"};return"undefined"!=typeof d.items?f.count=d.items:f.count=h.items,0===f.count||"0"===f.count?!1:((f.count<0||isNaN(f.count))&&(f.count=void 0),void(d.artist&&(f.artist=d.artist,"undefined"!=typeof d.artist_id&&(f.artist_id=d.artist_id),"undefined"!=typeof d.date&&(f.date=d.date),"undefined"!=typeof d.start_date&&"undefined"!=typeof d.end_date&&(f.date=d.start_date+","+d.end_date),"undefined"!=typeof d.location||"undefined"!=typeof d.lat&&"undefined"!=typeof d.lng||"undefined"!=typeof d.ip_address?("undefined"!=typeof d.location?f.location=d.location:"undefined"!=typeof d.lat&&"undefined"!=typeof d.lng?f.location=d.lat+","+d.lng:f.location=d.ip_address,"undefined"!=typeof d.distance&&(f.radius=d.distance),d.recommended===!0||"true"===d.recommended?("undefined"!=typeof d.exclude&&(f.only_recs=d.exclude),c.getRecommendedEventsFromArtistByLocation(f).then(function(b){return b?void g.concatToResults(a.getObjectByJsonData(b,e)):void 0})):c.getEventsFromArtistByLocation(f).then(function(b){return b?void g.concatToResults(a.getObjectByJsonData(b,e)):void 0})):c.getEventsFromArtist(f).then(function(b){b&&g.concatToResults(a.getObjectByJsonData(b,e))}))))})}}}]),angular.module("jtt_aping_bandsintown").service("apingBandsintownHelper",["apingModels","apingTimeHelper","apingUtilityHelper",function(a,b,c){this.getThisPlattformString=function(){return"bandsintown"},this.getThisPlatformLink=function(){return"http://bandsintown.com/"},this.compareStrings=function(a,b){return a.toLowerCase().trim().replace(/ /g,"")===b.toLowerCase().trim().replace(/ /g,"")},this.getArtistFromArray=function(a,b){var c={artist_name:void 0,artist_id:void 0,artist_link:void 0,img_url:void 0},d=!1;if(a.length>0){var e=this;angular.forEach(a,function(a,f){"undefined"==typeof a.name||d||e.compareStrings(a.name,b)&&(c={artist_name:a.name,artist_id:a.mbid||void 0,artist_link:a.website||a.facebook_tour_dates_url||void 0,img_url:a.image_url||a.thumb_url||void 0},d=!0)}),d||(c={artist_name:a[0].name,artist_id:a[0].mbid||void 0,artist_link:a[0].website||a[0].facebook_tour_dates_url||void 0,img_url:a[0].image_url||a[0].thumb_url||void 0})}return c},this.getObjectByJsonData=function(a,b){var c=[];if(a){var d=this;angular.forEach(a.data,function(a,e){if("undefined"==typeof b.items||b.items>0&&c.length<b.items){var f;f=b.getNativeData===!0||"true"===b.getNativeData?a:d.getItemByJsonData(a,b),f&&c.push(f)}})}return c},this.getItemByJsonData=function(a,b){var c={};if(a&&b.model)switch(b.model){case"event":c=this.getEventItemByJsonData(a,b);break;default:return!1}return c},this.getEventItemByJsonData=function(b,c){var d=a.getNew("event",this.getThisPlattformString());if(angular.extend(d,{start_timestamp:b.datetime?new Date(b.datetime).getTime():void 0,start_date_time:b.datetime?new Date(b.datetime):void 0,event_url:b.facebook_rsvp_url||void 0,ticket_url:b.ticket_url||void 0,intern_id:b.id||void 0,caption:b.title||void 0,source:b.artists||void 0,sold_out:b.ticket_status?"unavailable"===b.ticket_status:void 0}),b.artists&&b.artists.length>0){var e=this.getArtistFromArray(b.artists,c.artist);"undefined"!=typeof e.artist_name&&(d.artist_name=e.artist_name),"undefined"!=typeof e.artist_id&&(d.artist_id=e.artist_id),"undefined"!=typeof e.artist_link&&(d.artist_link=e.artist_link),"undefined"!=typeof e.img_url&&c.showAvatar&&(d.img_url=e.img_url)}return"undefined"!=typeof b.venue&&(d.place_name=b.venue.name||void 0,d.city=b.venue.city||void 0,d.country=b.venue.country||void 0,d.latitude=b.venue.latitude||void 0,d.longitude=b.venue.longitude||void 0),d}}]),angular.module("jtt_bandsintown",[]).factory("bandsintownFactory",["$http","bandsintownSearchDataService",function(a,b){var c={};return c.getArtist=function(c){var d=b.getNew("artist",c);return a.jsonp(d.url,{method:"GET",params:d.object})},c.getEventsFromArtist=function(c){var d=b.getNew("eventsFromArtist",c);return a.jsonp(d.url,{method:"GET",params:d.object})},c.getEventsFromArtistByLocation=function(c){var d=b.getNew("eventsFromArtistByLocation",c);return a.jsonp(d.url,{method:"GET",params:d.object})},c.getRecommendedEventsFromArtistByLocation=function(c){var d=b.getNew("recommendedEventsFromArtistByLocation",c);return a.jsonp(d.url,{method:"GET",params:d.object})},c}]).service("bandsintownSearchDataService",function(){this.getApiBaseUrl=function(a){return"http://api.bandsintown.com/"},this.fillDataInObjectByList=function(a,b,c){return angular.forEach(c,function(c,d){"undefined"!=typeof b[c]&&(a.object[c]=b[c])}),a},this.getNew=function(a,b){var c={object:{format:"json",api_version:"2.0",app_id:b.app_id||"angular-bandsintown-api-factory",callback:"JSON_CALLBACK"},url:""};switch("undefined"!=typeof b.limit&&(c.object.limit=b.limit),a){case"artist":c=this.fillDataInObjectByList(c,b,["artist_id"]),c.url=this.getApiBaseUrl()+"artists/"+b.artist+".json";break;case"eventsFromArtist":c=this.fillDataInObjectByList(c,b,["date","artist_id"]),c.url=this.getApiBaseUrl()+"artists/"+b.artist+"/events.json";break;case"eventsFromArtistByLocation":c=this.fillDataInObjectByList(c,b,["date","artist_id","location","radius"]),c.url=this.getApiBaseUrl()+"artists/"+b.artist+"/events/search.json";break;case"recommendedEventsFromArtistByLocation":c=this.fillDataInObjectByList(c,b,["date","artist_id","location","radius","only_recs"]),c.url=this.getApiBaseUrl()+"artists/"+b.artist+"/events/recommended"}return c}});