Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore committed Apr 30, 2018
1 parent 4c91001 commit 1319f27
Show file tree
Hide file tree
Showing 56 changed files with 4,926 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
package-lock.json*
yarn.lock*
yarn-error.log*
yarn-debug.log*
7 changes: 7 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
demo
node_modules
app.js
app.json
package-lock.json
project.config.json
.travis.yml
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "10"
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MIT License

Forked from [fanfou-sdk](https://github.com/LitoMore/fanfou-sdk-node)
Copyright (c) 2018 LitoMore

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
117 changes: 115 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,124 @@
# fanfou-sdk-weapp

[![](https://img.shields.io/travis/LitoMore/fanfou-sdk-weapp/master.svg)](https://travis-ci.org/LitoMore/fanfou-sdk-weapp)
[![](https://img.shields.io/npm/v/fanfou-sdk-weapp.svg)](https://www.npmjs.com/package/fanfou-sdk-weapp)
[![](https://img.shields.io/npm/l/fanfou-sdk-weapp.svg)](https://github.com/LitoMore/fanfou-sdk-weapp/blob/master/LICENSE)
[![](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

Fanfou SDK for WeApp

> The package is for WeApp, if you are developing with Node.js, please use [fanfou-sdk](https://github.com/LitoMore/fanfou-sdk-node).
## Install

```bash
$ npm i fanfou-sdk-weapp
```

Or you can copy the `src` directory to your project.

## Usage

```javascript
const Fanfou = require('fanfou-sdk-weapp')
// or
const Fanfou = require('./src/index')
```

**OAuth**

```javascript
const ff = new Fanfou({
consumerKey: '',
consumerSecret: '',
oauthToken: '',
oauthTokenSecret: ''
})

ff.get('/statuses/home_timeline', {format: 'html'})
.then(res => console.log(res))
.catch(err => console.log(err))
```

**XAuth**

```javascript
const ff = new Fanfou({
authType: 'xauth',
consumerKey: '',
consumerSecret: '',
username: '',
password: ''
})

ff.xauth()
.then(res => {
console.log(res)
ff.get('/statuses/public_timeline', {count: 10})
.then(res => console.log(res))
.catch(err => console.log(err))

ff.post('/statuses/update', {status: 'Hi Fanfou'})
.then(res => console.log(res))
.catch(err => console.log(err))
})

```

**Options**

- `authType`: Support `oauth` and `xuath`, default is `oauth`
- `consumerKey`: The consumer key
- `consumerSecret`: The consumer secret
- `oauthToken`: The OAuth token
- `oauthTokenSecret`: The OAuth token secret
- `username`: The Fanfou username
- `password`: The Fanfou password
- `protocol`: Set the prototol, default is `http:`
- `apiDomain`: Set the API domain, default is `api.fanfou.com`
- `oauthDomain`: Set the OAuth domain, default is `fanfou.com`

> For more Fanfou API docs, see the [Fanfou API doc](https://github.com/FanfouAPI/FanFouAPIDoc/wiki).
## API

```javascript
ff.xauth()
ff.get(uri, params)
ff.post(uri, params)
ff.upload(uri, filePaths, parameters)
```

**Examples**

```javascript
// OAuth
ff.get('/statuses/home_timeline', {})
.then(res => console.log(res))
.catch(err => console.log(err))

ff.post('/statuses/update', {status: 'post test'})
.then(res => console.log(res))
.catch(err => console.log(err))

ff.upload('/photos/upload', fileObject, {})
.then(res => console.log(res))
.catch(err => console.log(err))

// XAuth
ff.xauth()
.then(res => {
ff.get('/statuses/public_timeline', {})
.then(res => console.log(res))
.catch(err => console.log(err))
})
.catch(err => console.log(err))
```

## Related

- [fanta](https://github.com/LitoMore/fanta) - A new Fanfou WeApp
- [xiaofan](https://github.com/fanfoujs/xiaofan) - A classic Fanfou WeApp
- [xiaofan](https://github.com/fanfoujs/xiaofan) - WeApp for Fanfou
- [fanta](https://github.com/LitoMore/fanta) - Another WeApp for Fanfou
- [fanfou-sdk](https://github.com/LitoMore/fanfou-sdk-node) - Fanfou SDK for Node.js

## License
Expand Down
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
App({})
11 changes: 11 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"pages":[
"demo/demo"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle":"black"
}
}
44 changes: 44 additions & 0 deletions demo/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict'

const Fanfou = require('../src/index')

Page({
data: {
key: '2602578f6379ad3cc52b6269cb63d25c',
secret: '4676969b8faae10064caa2f19c36d5c0',
username: '',
password: ''
},

keyInput (e) {
const {value: key} = e.detail
this.setData({key})
},

secretInput (e) {
const {value: secret} = e.detail
this.setData({secret})
},

usernameInput (e) {
const {value: username} = e.detail
this.setData({username})
},

passwordInput (e) {
const {value: password} = e.detail
this.setData({password})
},

testTap () {
const {key: consumerKey, secret: consumerSecret, username, password} = this.data
const ff = new Fanfou({consumerKey, consumerSecret, username, password})

ff.xauth().then(res => {
console.log('token:', res.oauthToken)
console.log('secret:', res.oauthTokenSecret)
}).catch(err => {
console.log(err.message)
})
}
})
7 changes: 7 additions & 0 deletions demo/demo.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<view>
<input placeholder="consumer key" bindinput="keyInput" value="{{key}}" />
<input placeholder="consumer secret" bindinpu="secretInput" value="{{secret}}" />
<input placeholder="username" bindinput="usernameInput" />
<input placeholder="password" bindinput="passwordInput" password />
<button bindtap="testTap">TEST</button>
</view>
14 changes: 14 additions & 0 deletions demo/demo.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
input {
box-sizing: content-box;
border: 1px solid #ccc;
margin: 10px;
padding: 10px;
font-size: 14px;
}

button {
box-sizing: content-box;
border: 1px solid #ccc;
margin: 10px;
font-size: 14px;
}
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "fanfou-sdk-weapp",
"version": "0.0.0",
"description": "Fanfou SDK for WeApp",
"main": "src/index.js",
"scripts": {
"test": "standard"
},
"repository": {
"type": "git",
"url": "git+https://github.com/LitoMore/fanfou-sdk-weapp.git"
},
"author": "LitoMore",
"license": "MIT",
"bugs": {
"url": "https://github.com/LitoMore/fanfou-sdk-weapp/issues"
},
"homepage": "https://github.com/LitoMore/fanfou-sdk-weapp#readme",
"devDependencies": {
"standard": "^11.0.1"
},
"standard": {
"global": [
"Page",
"App",
"wx"
],
"ignore": [
"src/modules"
]
}
}
35 changes: 35 additions & 0 deletions project.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"description": "config file",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": false,
"es6": true,
"postcss": false,
"minified": false,
"newFeature": true
},
"compileType": "miniprogram",
"libVersion": "2.0.0",
"appid": "touristappid",
"projectname": "fanfou-sdk-weapp",
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"game": {
"currentL": -1,
"list": []
},
"miniprogram": {
"current": -1,
"list": []
}
}
}
48 changes: 48 additions & 0 deletions src/direct-message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict'

const timeago = require('./modules/timeago/index')
const dateFormat = require('./modules/date-format/index')
const User = require('./user')

class DirectMessage {
constructor (dm) {
this.id = dm.id
this.text = dm.text
this.sender_id = dm.sender_id
this.recipient_id = dm.recipient_id
this.created_at = dm.created_at
this.sender_screen_name = dm.sender_screen_name
this.recipient_screen_name = dm.recipient_screen_name
this.sender = new User(dm.sender)
this.recipient = new User(dm.recipient)
if (dm.in_reply_to) {
this.in_reply_to = new DirectMessage(dm.in_reply_to)
}

this.time_ago = this._getTimeAgo()
this.time_tag = this._getTimeTag()
}

_getTimeAgo () {
return timeago().format(this.created_at, 'fanfou_weapp')
}

_getTimeTag () {
const date = new Date()
const create = new Date(this.created_at)
const nowYear = dateFormat('yyyy', date)
const createYear = dateFormat('yyyy', create)
const nowDate = dateFormat('yyyyMMdd', date)
const createDate = dateFormat('yyyyMMdd', create)

if (nowDate === createDate) {
return dateFormat('hh:mm', create)
}
if (nowYear === createYear) {
return dateFormat('MM/dd hh:mm', create)
}
return dateFormat('yyyy/MM/dd hh:mm', create)
}
}

module.exports = DirectMessage
Loading

0 comments on commit 1319f27

Please sign in to comment.