https://github.com/iij/mruby-webapi
WebAPI client for mruby
https://github.com/iij/mruby-webapi
Last synced: 5 months ago
JSON representation
WebAPI client for mruby
- Host: GitHub
- URL: https://github.com/iij/mruby-webapi
- Owner: iij
- Created: 2014-08-27T02:33:56.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-04-03T07:51:01.000Z (about 8 years ago)
- Last Synced: 2023-03-28T21:11:11.921Z (about 2 years ago)
- Language: Ruby
- Size: 14.6 KB
- Stars: 4
- Watchers: 9
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mruby-webapi
"mruby-webapi" is a WebAPI client library.
## API
- WebAPI.new url, opts={}
- Make an WebAPI object to be used to call APIs whose base url is `url`
- Supported keys in `opts`:
- :accept_encoding => str (mruby-zlib is required)
- acceptable response encoding
(supported type: "gzip" or "deflate")
- :certs => str
- pathname of the file contains trusted root CA certificate(s)
- :content_encoding => str (mruby-zlib is required)
- type of request body encoding
(supported type: "gzip" or "deflate")
- :content_type => str
- "Content-Type" of the request body (if any)
- :headers => Hash
- arbitrary header fields.
- :ignore_certificate_validity => boolean
- ignore "Not Before" and "Not After" fields of certificates
(see https://github.com/iij/mruby-tls-openssl)
- :proxy => str
- URL of HTTPS proxy
- :sni => false (default) | true | String
- use Server Name Indication (SNI)
(see https://github.com/iij/mruby-tls-openssl)- WebAPI#get resource
- WebAPI#post resource, data
- WebAPI.urlencode pairs
- `pairs` can be Hash or Array (like `[[key1, value1], [key2, value2], ...]`)
- WebAPI.urldecode str## Example
```Ruby
api = WebAPI.new "https://api.github.com/", {
:certs => "digicert.crt",
:content_type => "application/json",
:headers => {
"X-AnyHeader" => "Some Text"
}
}
md = JSON.generate({
"text" => "Hello world github/linguist#1 **cool**, and #1!",
"mode" => "gfm",
"context" => "github/gollum"
})
# or md = '{"text":"Hello world"}'
puts "* Request Message (for debug):"
puts api.post_str "/markdown", mdputs
puts "* API Response Body:"
response = api.post "/markdown", md
html = response.body
puts html
``````
* Request Message (for debug):
POST /markdown HTTP/1.1
Host: api.github.com:443
Connection: close
User-Agent: mruby-webapi
Content-Type: application/json
Content-Length: 97
X-AnyHeader: Some Text{"text":"Hello world github/linguist#1 **cool**, and #1!","mode":"gfm","context":"github/gollum"}
* API Response Body:
Hello world github/linguist#1 cool, and #1!
```## License
Copyright (c) 2014 Internet Initiative Japan Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.