Skip to content

Commit

Permalink
Merge pull request #2 from zztkm/return-body-when-t-is-string
Browse files Browse the repository at this point in the history
Return body when t is string
  • Loading branch information
zztkm authored Oct 11, 2022
2 parents 590465a + 0edda20 commit 5868e9e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[microCMS](https://microcms.io/) sdk for v language.

repo: https://github.com/zztkm/microcms-v-sdk

## Installation and Import

### Using vpm
Expand All @@ -18,6 +20,12 @@ Import
import zztkm.microcms
```

### Directly from GitHub

```shell
v install --git https://github.com/zztkm/microcms-v-sdk
```

## Usage

TODO: 使い方をがんばって記載する
Expand Down
20 changes: 16 additions & 4 deletions contents.v
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,34 @@ fn make_get_query(p GetContentParams) urllib.Values {
// The retrieved content is stored in the type parameter T and returned.
pub fn (c Client) content_list<T>(p GetContentListParams) ?T {
req := c.new_request(.get, p.endpoint, make_list_query(p))?

res := send_request(req)?

return json.decode(T, res.body)
}

// content_list is a method to retrieve a content list.
// If you want to decode your own, use this one.
pub fn (c Client) content_list_str(p GetContentListParams) ?string {
req := c.new_request(.get, p.endpoint, make_list_query(p))?
res := send_request(req)?
return res.body
}

// content is a method to retrieve a single content.
// The retrieved content is stored in the type parameter T and returned.
pub fn (c Client) content<T>(p GetContentParams) ?T {
req := c.new_request(.get, '$p.endpoint/$p.content_id', make_get_query(p))?

res := send_request(req)?

return json.decode(T, res.body)
}

// content_str is a method to retrieve a single content.
// If you want to decode your own, use this one.
pub fn (c Client) content_str(p GetContentParams) ?string {
req := c.new_request(.get, '$p.endpoint/$p.content_id', make_get_query(p))?
res := send_request(req)?
return res.body
}

fn make_create_query(p CreateParams) urllib.Values {
mut v := urllib.new_values()
if p.status.len > 0 {
Expand Down
2 changes: 1 addition & 1 deletion v.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Module {
name: 'microcms'
description: ''
version: '0.1.0'
version: '0.2.0'
license: 'MIT'
dependencies: []
}

0 comments on commit 5868e9e

Please sign in to comment.