Skip to content

Commit

Permalink
Merge pull request #1872 from h3poteto/feat/search-type
Browse files Browse the repository at this point in the history
Put type param into options in search
  • Loading branch information
h3poteto authored Aug 27, 2023
2 parents 8904072 + 1ac65c4 commit f765132
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion example/typescript/src/mastodon/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const access_token: string = process.env.MASTODON_ACCESS_TOKEN
const client = generator('mastodon', BASE_URL, access_token)

client
.search('whalebird', 'hashtags', { resolve: true })
.search('whalebird', { type: 'hashtags', resolve: true })
.then((resp: Response<Entity.Results>) => {
console.log(resp.data.hashtags)
})
Expand Down
2 changes: 1 addition & 1 deletion example/typescript/src/misskey/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const access_token: string = process.env.MISSKEY_ACCESS_TOKEN!
const client = generator('misskey', 'https://misskey.io', access_token)

client
.search('h3poteto', 'accounts')
.search('h3poteto', { type: 'accounts' })
.then(res => console.log(res.data))
.catch(err => {
if (isCancel(err)) {
Expand Down
2 changes: 1 addition & 1 deletion example/typescript/src/pleroma/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const access_token: string = process.env.PLEROMA_ACCESS_TOKEN!
const client = generator('pleroma', BASE_URL, access_token)

client
.search('whalebird', 'hashtags', { resolve: true })
.search('whalebird', { resolve: true })
.then((resp: Response<Entity.Results>) => {
console.log(resp.data.hashtags)
})
Expand Down
12 changes: 8 additions & 4 deletions megalodon/src/friendica.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2552,7 +2552,7 @@ export default class Friendica implements MegalodonInterface {
* GET /api/v2/search
*
* @param q The search query.
* @param type Enum of search target.
* @param options.type Enum of search target.
* @param options.limit Maximum number of results to load, per type. Defaults to 20. Max 40.
* @param options.max_id Return results older than this id.
* @param options.min_id Return results immediately newer than this id.
Expand All @@ -2564,8 +2564,8 @@ export default class Friendica implements MegalodonInterface {
*/
public async search(
q: string,
type: 'accounts' | 'hashtags' | 'statuses',
options?: {
type?: 'accounts' | 'hashtags' | 'statuses'
limit?: number
max_id?: string
min_id?: string
Expand All @@ -2577,10 +2577,14 @@ export default class Friendica implements MegalodonInterface {
}
): Promise<Response<Entity.Results>> {
let params = {
q,
type
q
}
if (options) {
if (options.type) {
params = Object.assign(params, {
type: options.type
})
}
if (options.limit) {
params = Object.assign(params, {
limit: options.limit
Expand Down
10 changes: 7 additions & 3 deletions megalodon/src/mastodon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2877,8 +2877,8 @@ export default class Mastodon implements MegalodonInterface {
*/
public async search(
q: string,
type: 'accounts' | 'hashtags' | 'statuses',
options?: {
type?: 'accounts' | 'hashtags' | 'statuses'
limit?: number
max_id?: string
min_id?: string
Expand All @@ -2890,10 +2890,14 @@ export default class Mastodon implements MegalodonInterface {
}
): Promise<Response<Entity.Results>> {
let params = {
q,
type
q
}
if (options) {
if (options.type) {
params = Object.assign(params, {
type: options.type
})
}
if (options.limit) {
params = Object.assign(params, {
limit: options.limit
Expand Down
4 changes: 2 additions & 2 deletions megalodon/src/megalodon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ export interface MegalodonInterface {
* Perform a search.
*
* @param q The search query.
* @param type Enum of search target.
* @param options.type Enum of search target.
* @param options.limit Maximum number of results to load, per type. Defaults to 20. Max 40.
* @param options.max_id Return results older than this id.
* @param options.min_id Return results immediately newer than this id.
Expand All @@ -1229,8 +1229,8 @@ export interface MegalodonInterface {
*/
search(
q: string,
type: 'accounts' | 'hashtags' | 'statuses',
options?: {
type?: 'accounts' | 'hashtags' | 'statuses'
limit?: number
max_id?: string
min_id?: string
Expand Down
6 changes: 3 additions & 3 deletions megalodon/src/misskey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1951,8 +1951,8 @@ export default class Misskey implements MegalodonInterface {
// ======================================
public async search(
q: string,
type: 'accounts' | 'hashtags' | 'statuses',
options?: {
options: {
type: 'accounts' | 'hashtags' | 'statuses'
limit?: number
max_id?: string
min_id?: string
Expand All @@ -1963,7 +1963,7 @@ export default class Misskey implements MegalodonInterface {
exclude_unreviewed?: boolean
}
): Promise<Response<Entity.Results>> {
switch (type) {
switch (options.type) {
case 'accounts': {
let params = {
query: q
Expand Down
12 changes: 8 additions & 4 deletions megalodon/src/pleroma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2880,7 +2880,7 @@ export default class Pleroma implements MegalodonInterface {
* GET /api/v2/search
*
* @param q The search query.
* @param type Enum of search target.
* @param options.type Enum of search target.
* @param options.limit Maximum number of results to load, per type. Defaults to 20. Max 40.
* @param options.max_id Return results older than this id.
* @param options.min_id Return results immediately newer than this id.
Expand All @@ -2892,8 +2892,8 @@ export default class Pleroma implements MegalodonInterface {
*/
public async search(
q: string,
type: 'accounts' | 'hashtags' | 'statuses',
options?: {
type?: 'accounts' | 'hashtags' | 'statuses'
limit?: number
max_id?: string
min_id?: string
Expand All @@ -2905,10 +2905,14 @@ export default class Pleroma implements MegalodonInterface {
}
): Promise<Response<Entity.Results>> {
let params = {
q,
type
q
}
if (options) {
if (options.type) {
params = Object.assign(params, {
type: options.type
})
}
if (options.limit) {
params = Object.assign(params, {
limit: options.limit
Expand Down

0 comments on commit f765132

Please sign in to comment.