Skip to content

Commit 2a4479f

Browse files
committed
refactor: api
1 parent 6cbd340 commit 2a4479f

File tree

13 files changed

+50
-49
lines changed

13 files changed

+50
-49
lines changed

android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ android {
138138
applicationId "github.funnyzak.v2ex"
139139
minSdkVersion rootProject.ext.minSdkVersion
140140
targetSdkVersion rootProject.ext.targetSdkVersion
141-
versionCode 35
142-
versionName "0.8.3"
141+
versionCode 36
142+
versionName "0.8.4"
143143
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
144144

145145
if (isNewArchitectureEnabled()) {

ios/app.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@
494494
"$(inherited)",
495495
"@executable_path/Frameworks",
496496
);
497-
MARKETING_VERSION = 0.8.3;
497+
MARKETING_VERSION = 0.8.4;
498498
OTHER_LDFLAGS = (
499499
"$(inherited)",
500500
"-ObjC",
@@ -528,7 +528,7 @@
528528
"$(inherited)",
529529
"@executable_path/Frameworks",
530530
);
531-
MARKETING_VERSION = 0.8.3;
531+
MARKETING_VERSION = 0.8.4;
532532
OTHER_LDFLAGS = (
533533
"$(inherited)",
534534
"-ObjC",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "v2hub",
3-
"version": "0.8.3",
3+
"version": "0.8.4",
44
"description": "This project used React Native to build a V2EX mobile client application. The main goal was to build a React Native rapid development scaffold.",
55
"main": "index.js",
66
"private": false,

src/actions/MemberActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export const unFollowPeople = (member: AppObject.Member) => async (dispatch: Dis
105105
dispatch(cacheMemberFollowing(getState().member.followPeoples))
106106
}
107107

108-
export const setCurrentToken = (token?: AppObject.MToken) => ({
108+
export const setCurrentToken = (token?: AppObject.MemberToken) => ({
109109
type: APP_AUTH,
110110
payload: token
111111
})
@@ -121,7 +121,7 @@ export const loginByToken = (token: string) => async (dispatch: Dispatch) => {
121121
}
122122
}
123123

124-
const loginByTokenSuccess = (token: AppObject.MToken) => async (dispatch: Dispatch, getState: () => RootState) => {
124+
const loginByTokenSuccess = (token: AppObject.MemberToken) => async (dispatch: Dispatch, getState: () => RootState) => {
125125
await AsyncStorage.setItem(MEMBER_TOKEN_KEY, token.token)
126126

127127
ApiLib.setToken(token.token)

src/api/index.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,23 @@ const defaultConfiguration = {
2323
}
2424

2525
class V2ex {
26-
configuration: AppAPI.BaseConfiguration = defaultConfiguration
26+
configuration: AppAPI.APIConfiguration = defaultConfiguration
2727
root_path?: string
2828
token?: string
29-
reply: AppAPI.Reply = reply(this)
30-
member: AppAPI.Member = member(this)
31-
node: AppAPI.Node = node(this)
32-
topic: AppAPI.Topic = topic(this)
33-
notification: AppAPI.Notification = notification(this)
29+
reply: AppAPI.ReplyAPI = reply(this)
30+
member: AppAPI.MemberAPI = member(this)
31+
node: AppAPI.NodeAPI = node(this)
32+
topic: AppAPI.TopicAPI = topic(this)
33+
notification: AppAPI.NotificationAPI = notification(this)
34+
35+
constructor(options?: AppAPI.APIConfiguration) {
36+
if (options) {
37+
this.setOptions(options)
38+
}
39+
this.init()
40+
}
3441

35-
setOptions(options: AppAPI.BaseConfiguration) {
42+
setOptions(options: AppAPI.APIConfiguration) {
3643
this.configuration = _.merge(this.configuration, options)
3744
this.root_path = `/${this.configuration.store}`
3845

@@ -106,7 +113,7 @@ class V2ex {
106113

107114
send<T>(
108115
path: string,
109-
method: AppAPI.Method,
116+
method: AppAPI.HttpMethod,
110117
headers?: { [name: string]: string },
111118
params?: Record<string, string>,
112119
data?: any,
@@ -138,13 +145,6 @@ class V2ex {
138145
headers = _.merge(_headers, headers)
139146

140147
return new Promise<T>((resolve, reject) => {
141-
// console.log({
142-
// uri,
143-
// method,
144-
// headers,
145-
// data,
146-
// ...params
147-
// })
148148
fetch(uri, { method, headers, body: JSON.stringify(data) })
149149
.then((response: Response) => {
150150
if (response.ok) {

src/api/lib/member/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AppAPI, AppObject } from '../../types'
22

3-
export default (v2ex: AppAPI.APP): AppAPI.Member => ({
4-
myToken: () => v2ex.get<AppObject.MToken>('/token', undefined, undefined, undefined, 'v2'),
3+
export default (v2ex: AppAPI.APP): AppAPI.MemberAPI => ({
4+
myToken: () => v2ex.get<AppObject.MemberToken>('/token', undefined, undefined, undefined, 'v2'),
55

66
myProfile: () => v2ex.get<AppObject.Member>('/member', undefined, undefined, undefined, 'v2'),
77

@@ -15,7 +15,7 @@ export default (v2ex: AppAPI.APP): AppAPI.Member => ({
1515
),
1616

1717
token: (token: string) =>
18-
v2ex.get<AppObject.MToken>(
18+
v2ex.get<AppObject.MemberToken>(
1919
`/token`,
2020
{
2121
Authorization: `Bearer ${token}`

src/api/lib/node/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AppAPI, AppObject } from '../../types'
22

3-
export default (v2ex: AppAPI.APP): AppAPI.Node => ({
3+
export default (v2ex: AppAPI.APP): AppAPI.NodeAPI => ({
44
get: (id: string | number, version: AppAPI.API_VERSION): Promise<AppObject.Node> =>
55
v2ex.get<AppObject.Node>(
66
version === 'v2' ? `/nodes/${id}` : `/nodes/show.json?${typeof id === 'string' ? 'name' : 'id'}=${id}`,

src/api/lib/notification/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AppAPI, AppObject } from '../../types'
22

3-
export default (v2ex: AppAPI.APP): AppAPI.Notification => ({
3+
export default (v2ex: AppAPI.APP): AppAPI.NotificationAPI => ({
44
/**
55
* Get my latest notifications
66
*/

src/api/lib/reply/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AppAPI, AppObject } from '../../types'
22

3-
export default (v2ex: AppAPI.APP): AppAPI.Reply => ({
3+
export default (v2ex: AppAPI.APP): AppAPI.ReplyAPI => ({
44
/**
55
* Get topic replies
66
* @param topic_id : topic id

src/api/lib/topic/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AppAPI, AppObject } from '../../types'
22

3-
export default (v2ex: AppAPI.APP): AppAPI.Topic => ({
3+
export default (v2ex: AppAPI.APP): AppAPI.TopicAPI => ({
44
/**
55
* pager note topic list by api version 2
66
* @param name : node name

0 commit comments

Comments
 (0)