0.0
No commit activity in last 3 years
No release in over 3 years
Simple wrapper for the RubyChina API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0

Runtime

>= 0
>= 0
 Project Readme

RubychinaApi

为了了解如何用Ruby写Web api wrapper做的实验

Installation

gem 'rubychina_api'

Usage

Api手册

https://ruby-china.org/api/

登录

RubychinaApi::Config.client_id = "blabla"
RubychinaApi::Config.secret = "blabla"

RubychinaApi::Client.login("username" => "name", "password" => "xxxx")
=> #<RubychinaApi::Client:0x007fda3cdf98f0
 @avatar_url=
  "https://ruby-china-files.b0.upaiyun.com/user/large_avatar/xxxxx.jpg",
 @id=xxxxx,
 @meta=nil,
 @name="xxxx">

Api请求

使用get、post方法请求数据

response = RubychinaApi::Operation.get("topics")
JSON.parse(response.body)["topics"].last.fetch("title")
=> "Rails- 让我欢喜让我忧!"

需要二级url时,增加参数

response = RubychinaApi::Operation.get("topics", "24325")
JSON.parse(response.body).dig("topic","title")
=> "《提问的智慧》"

需要params时,增加hash作为尾参数

response = RubychinaApi::Operation.get("topics", {"type": "no_reply"})
JSON.parse(response.body)["topics"].first.fetch("id")
=> "给指定 url POST 包的时候,用 YAML.load_file 方法:当 YML 文件内有汉字时,报 utf-8 错"

License

The gem is available as open source under the terms of the MIT License.