This repository has been archived by the owner on Jul 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog.coffee
86 lines (72 loc) · 2.52 KB
/
blog.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
angular.module('caste.services')
.value('BlogConfig',
contributors: ['zandertaketomo', 'chrismulhern', 'waltwolfe']
blog: 'casteblog'
photo: 'castequality'
projects: 'casteproject'
rootUrl: '//api.tumblr.com/v2/blog'
defaultParams:
api_key: 'NvWaTzI30JItCIsWNf5UQe3BlI85yZ1Fq70aYiB77X4Z93wtj0'
jsonp: 'JSON_CALLBACK'
)
.service 'Blog', ($http, $q, BlogConfig) ->
@offset = 0
@limit = 2
@total = 0
@about = {}
@projects = {}
@posts = []
@photos = []
@visuals = []
@loading = false
@canLoad = () =>
!@loading and @offset < @total
@url = (contributor, endpoint = "posts") =>
"#{BlogConfig.rootUrl}/#{contributor}.tumblr.com/#{endpoint}"
@params = =>
angular.extend angular.copy(BlogConfig.defaultParams),
offset: @offset
limit: @limit
@getPosts = =>
@loading = true
@query(BlogConfig.blog).success((data) =>
@total = data.response.total_posts
for post in data.response.posts
@posts.push post
@offset += 1
# once done loading, flip the switch
@loading = false
).error((error) ->
# once done loading, flip the switch
@loading = false
)
@getProjects = (active) =>
@query(BlogConfig.projects, type: 'photo').success (data) =>
for project in data.response.posts
project.pages = project.photos
if project.caption?.length
project.pages.push
media: project.caption
active: active
@projects[project.timestamp] = project
@getPhotos = =>
@query(BlogConfig.photo, type: 'photo', limit: null, offset: null).success (data) =>
for post in data.response.posts
for photo in post.photos
@photos.push photo
@getVisuals = =>
promises = for contributor in BlogConfig.contributors
# args.tag = 'castequality'
@query contributor, type: 'photo'
$q.all(promises).then (results) =>
for result in results
for post in result.data.response.posts
for photo in post.photos
@visuals.push photo
@getAbout = () =>
$http.jsonp(@url(BlogConfig.photo, "info"), params: @params()).success (data) =>
blog = data?.response?.blog
@about.title = blog?.title
@about.description = blog?.description
@query = (contributor, params = {}) =>
$http.jsonp @url(contributor), params: angular.extend(@params(), params)