Skip to content

Commit

Permalink
Update package version => 0.0.7 (#1)
Browse files Browse the repository at this point in the history
* Update package version => 0.0.7

* Update vs.js

* Build

* Recrypt npm token

* Modify about search

* Modify about url fns

* Modify v1.js condition
  • Loading branch information
kthjm authored Jul 27, 2018
1 parent 8b578f6 commit 02adc9a
Show file tree
Hide file tree
Showing 8 changed files with 451 additions and 96 deletions.
36 changes: 18 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
language: node_js
node_js:
- '8'
cache:
yarn: true
directories:
- node_modules
after_success:
- yarn coverage
deploy:
provider: npm
email: toxictoxer@gmail.com
on:
tags: true
repo: chooslr/tumblrinbrowser
branch: publish
api_key:
secure: ZFJpN9hjqLi4tKAI+ryFrC+5Q6evL5Qrac+iSJOV3ibmzsxC8LXeh5Lqr9jTN501EW4EWnghJCWQcHHTTVUvuglQZ6QHCfqCDBEp/bwqS7W8AqTXwymaSD8oz7b5j2xnKB6Qwif58Qc7Q6pA8ImgS+FWlPuPMddrzMpuLxsnpYyzTptpF7Vrvm97lmK7hTbdcfJ0W+XdXenFVMm9v0RnuqTFf2EhEUIoKFAX/Owffh8uh9VkqOdosaxg1Dt21BGmPsXcSMWmZFMP/FfSHhty2iFB3pFukekEsZw5lHMRbFS8hFctR441fVs4+RX7x7FzJtGFAJURQveCLXquWhfyvIzBhLxgbHVGVY2FBptwVhG0KbzRgzwqooq7GxcIPwxmXwR8uavi6NNmYoNXWuFy96vA27wuVgypQUdTfSNmJ2J87WMs2VhynmNYtuKqBf85KtmOjhELF06/4siJp6hpY7feONrNXNAuC1ysAHbXGoXMyIDfyCSF7GoWXj0hRVxAmdxUNaW8h8AAevIbd++phUV21xkWGYkUrd2AKpbTSDV8em4FHkIjNhJTQKABcfPhsq4f9KQDN8ALCFZGfNUTXASaJ2lIvaiGnBQkZXZOTUJbdWqtffxbS3VXyKAhA8nO7WrOPBZtC7mLYjQim4Aa8Z9hy8fyf4/Nd28Nh0o2jP4=
language: node_js
node_js:
- '8'
cache:
yarn: true
directories:
- node_modules
after_success:
- yarn coverage
deploy:
provider: npm
email: toxictoxer@gmail.com
on:
tags: true
repo: chooslr/tumblrinbrowser
branch: publish
api_key:
secure: KRf4gd0N3KQ0qY9wBMu3Yxst3ukyefA1QgG0wZwFa7NO+hPKgr3+OTJemyb4QZ9HKFY16EkqSk35uxYL2jtfaD5xAiMjw2TZWrTPyhvQ1x7rQuHKNcAqiKSJfpagcuIOLC8mmK1N8NN7qX7g0+RgapdKGe4JafX8kQlU9PHWmDOZ2HgEiMAZ549946hn49mps73FW7Ya5Xt2MM5np9QK8KP3amqwpbfjQU0gbf1vjd38fSeuXDPh7/q0PHqObsl0wyPnSBI8W0vDrsAnKX5qd0TpFC4yZfzK3GBTtEztOhMGwvsATzI/FJrdAbDZswM38ESy5ykkopCVzp6wLrDdWRYRTRvABK2xaE/G8HUZdhzl9U/33bG+j1X8zzulfnTt71CUzpF77c8VyZKdfoXDJ9n/In3wK25DxgCdAc5YWeDnmEgV91Zh2oUHpGoPlBpTUxHU+/ufyu1iyuGeQEUW96rdMxFtosyyyBehpfmRgcNrXpMS7Hvo4DKsnUdLBjt9kDJTPb3KCVmXUunXo8HBqZKLhKnFP/tbV5lkp8rKMX+ZUgOzJps1ETvuzATQJcHDyypthPe9D02Q2aJnW9YJiMhjfd/XPKDN4XYBjKjL+Ox+mUQr241DD9IvwNUSZ+S8vwF+mELXio4vuxhtS6Mg0VeRu+dNkpVsSyqN/sfHVu4=
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import Tumblr from 'tumblrinbrowser'
const tumblr = new Tumblr({ api_key, proxy })
```

### `new Tumblr({ api_key, proxy })`
### new Tumblr({ api_key, proxy })
Required at least one either.

#### `.blog(name)`
#### .blog(name)
result: `Promise<Blog>`

#### `.posts(name[, params])`
#### .posts(name[, params])
result: `Promise<Post[]>`
##### params
- `type`
Expand All @@ -47,27 +47,27 @@ result: `Promise<Post[]>`
- `notes_info`
- `filter`

#### `.total(name[, params])`
#### .total(name[, params])
result: `Promise<number>`
##### params
- `type`
- `tag`

#### `.post(name, id[, params])`
#### .post(name, id[, params])
result: `Promise<Post>`
##### params
- `reblog_info`
- `notes_info`

#### `.samplingPosts(options)` / `.samplingTags(options)`
#### .samplingPosts(options) / .samplingTags(options)
result: `Promise<Post[]>` / `Promise<Tag[]>`
##### options
- `name`
- `denom`
- `maxLimit`
- `params`

#### `.generatePosts(options)`
#### .generatePosts(options)
```js
const supply = await tumblr.generatePosts({ name })
const { done, value: posts } = await supply()
Expand Down Expand Up @@ -105,12 +105,16 @@ const blog = await v1.blog(name[, timeout])
const posts = await v1.posts(name[, params, timeout])
const total = await v1.total(name[, params, timeout])
const post = await v1.post(name, id[, params, timeout])
const posts = await v1.search(name, word[, page, timeout])

const posts = await v1.samplingPosts({ name, params, denom, maxLimit, timeout })
const tags = await v1.samplingTags({ name, params, denom, maxLimit, timeout })

const supply = await v1.generatePosts({ name, params, random, timeout })
const supply = await v1.generateSearch({ name, word, timeout })
```

- [Always serve blog over SSL.](https://security.tumblr.com/post/166219476810/support-support-ssl-security-which-has-been)

## License
MIT (http://opensource.org/licenses/MIT)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tumblrinbrowser",
"version": "0.0.6",
"version": "0.0.7",
"author": "kthjm <toxictoxer@gmail.com>",
"repository": "chooslr/tumblrinbrowser",
"license": "MIT",
Expand Down
58 changes: 56 additions & 2 deletions src/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ import {
postsToTags
} from './util.js'

const API_URL = name => `https://${identifier(name)}/api/read/json`
const PAGE_URL = (name) => `https://${identifier(name)}`
const API_URL = (name) => `${PAGE_URL(name)}/api/read/json`
const SEARCH_URL = (name, word) => `${PAGE_URL(name)}/search/${word}`

const MAX_LIMIT = 50
const TIMEOUT = 5000

export const postTypes = ['quote', 'text', 'chat', 'photo', 'link', 'video', 'audio']

const jsonpInterface = (name, params, timeout = 5000) => {
const jsonpInterface = (name, params, timeout = TIMEOUT) => {
asserts(typeof name === 'string', 'required name')
const { start, num, type, tag, id, filter } = params || {}
return jsonp(
Expand Down Expand Up @@ -45,6 +49,16 @@ export const post = (name, id, timeout) => {
.then(({ posts }) => posts[0])
}

export const search = (name, word, page, timeout = TIMEOUT) => {
asserts(word && typeof word === 'string', 'required word')
page = (typeof page === 'number' && page > 0) ? page : 1
return jsonp(
SEARCH_URL(name, word) + joinParams({ format: 'json', page }),
timeout
)
.then(({ posts }) => posts)
}


export const samplingTags = (...arg) => samplingPosts(...arg).then(postsToTags)

Expand Down Expand Up @@ -111,4 +125,44 @@ export const generatePosts = async ({ name, random, params, timeout } = {}) => {
timeout
)
})
}

export const generateSearch = async ({ name, word, timeout } = {}) => {

let tempPosts = await search(name, word, 1, timeout)
asserts(tempPosts.length > 0, 'not found')

const pageIterator = pageGenerator()

return () => {

const { value: page, done } = pageIterator.next()

if (done) {
const value = tempPosts
if (tempPosts.length) tempPosts = []
return Promise.resolve({ value, done })
}

return search(name, word, page + 1, timeout).then(posts => {
pageIterator.next(!posts.length || posts.length !== tempPosts.length)
const value = tempPosts
tempPosts = posts
return { value, done }
})
}
}

function* pageGenerator () {
let page = 1
let isReturn
while (true) {
if (!isReturn) {
isReturn = yield page
yield
} else {
return page
}
page++
}
}
17 changes: 17 additions & 0 deletions test/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import assert from 'assert'
import { search, generateSearch } from '../rewired.v1.js'
import { recursiveAddPostTillDone } from '../src/util.js'

const recursiveTillEmpty = (name, word, page = 1, set = new Set()) =>
search(name, word, page).then(posts => {
posts.forEach(post => set.add(post))
return !posts.length ? [...set.values()] : recursiveTillEmpty(name, word, page + 1, set)
})

it('equal search() and generateSearch()', async () => {
const name = 'staff'
const word = 'future'
const postsBySingle = await recursiveTillEmpty(name, word)
const postsByGenerate = await generateSearch({ name, word }).then(recursiveAddPostTillDone)
assert.equal(postsBySingle.length, postsByGenerate.length)
})
Loading

0 comments on commit 02adc9a

Please sign in to comment.