Add status and conversation fetching to apiService.

This commit is contained in:
Roger Braun 2016-11-24 18:16:20 +01:00
parent a5f523922c
commit 18c11e405a
1 changed files with 16 additions and 6 deletions

View File

@ -7,18 +7,16 @@ const FAVORITE_URL = '/api/favorites/create'
const UNFAVORITE_URL = '/api/favorites/destroy' const UNFAVORITE_URL = '/api/favorites/destroy'
const RETWEET_URL = '/api/statuses/retweet' const RETWEET_URL = '/api/statuses/retweet'
const STATUS_UPDATE_URL = '/api/statuses/update.json' const STATUS_UPDATE_URL = '/api/statuses/update.json'
const STATUS_URL = '/api/statuses/show'
const MEDIA_UPLOAD_URL = '/api/statusnet/media/upload' const MEDIA_UPLOAD_URL = '/api/statusnet/media/upload'
// const CONVERSATION_URL = '/api/statusnet/conversation/'; const CONVERSATION_URL = '/api/statusnet/conversation'
// const FORM_CONTENT_TYPE = {'Content-Type': 'application/x-www-form-urlencoded'}; const oldfetch = window.fetch
// import { param, ajax } from 'jquery';
// import { merge } from 'lodash';
let fetch = (url, options) => { let fetch = (url, options) => {
const baseUrl = '' const baseUrl = ''
const fullUrl = baseUrl + url const fullUrl = baseUrl + url
return window.fetch(fullUrl, options) return oldfetch(fullUrl, options)
} }
const authHeaders = (user) => { const authHeaders = (user) => {
@ -29,6 +27,16 @@ const authHeaders = (user) => {
} }
} }
const fetchConversation = ({id}) => {
let url = `${CONVERSATION_URL}/${id}.json?count=100`
return fetch(url).then((data) => data.json())
}
const fetchStatus = ({id}) => {
let url = `${STATUS_URL}/${id}.json`
return fetch(url).then((data) => data.json())
}
const fetchTimeline = ({timeline, credentials, since = false, until = false}) => { const fetchTimeline = ({timeline, credentials, since = false, until = false}) => {
const timelineUrls = { const timelineUrls = {
public: PUBLIC_TIMELINE_URL, public: PUBLIC_TIMELINE_URL,
@ -108,6 +116,8 @@ const uploadMedia = ({formData, credentials}) => {
const apiService = { const apiService = {
verifyCredentials, verifyCredentials,
fetchTimeline, fetchTimeline,
fetchConversation,
fetchStatus,
favorite, favorite,
unfavorite, unfavorite,
retweet, retweet,