Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/resource-watch/api-sdk
Ruby interface to the Resource Watch Gateway
https://github.com/resource-watch/api-sdk
Last synced: 1 day ago
JSON representation
Ruby interface to the Resource Watch Gateway
- Host: GitHub
- URL: https://github.com/resource-watch/api-sdk
- Owner: resource-watch
- Created: 2017-01-25T10:03:46.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-17T10:12:54.000Z (over 7 years ago)
- Last Synced: 2024-04-09T11:25:01.313Z (7 months ago)
- Language: Ruby
- Size: 53.7 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Resource Watch API SDK
This gem provides an ActiveModel interface for connecting ruby applications with the Resource Watch API.
## Usage
Add the line `gem 'rw_api_sdk', :git => 'git://github.com/resource-watch/api-sdk.git'` in your Gemfile and set the environment variable `GFW_API_URL' to the API URL you want to target (with no trailing slash!). You're all set.
This gem exposes several classes in the module APISdk, corresponding to different Resource Watch API endpoints. Datasets are exposed as the APISdk::Dataset class. Right now, you can do several things with a Dataset —but only the mandatory fields are supported:
Find a dataset in the API:
```
> require 'api_sdk'
=> true
> dataset = APISdk::Dataset.find("1f6b48e6-a32e-4c0b-8b86-8285849bab63")
=> #, @messages={}, @details={}>, @persisted=true, @previously_changed={}>
```You can modify its attributes:
```
> dataset.name = "New name"
=> "New name"
```But as the name has changed, now its attributes are not equal to those of the API dataset.
```
> dataset.persisted?
=> false
```You can inspect the changes and rollback them:
```
> dataset.changes
=> {"name" => ["Old name", "New name"]}
> dataset.rollback!
=> ["name"]
> dataset.name
=> "Old name"
```So now there are no differences between your object and the API dataset.
```
> dataset.persisted?
=> true
> a.changes
=> {}
```The changes you make are validated:
```
> dataset.name = nil
> dataset.valid?
=> false
> dataset.errors.to_hash
=> {:name => ["can't be blank"]}
```When you are done, you can update the object and persist it to the API
```
> dataset.name = "A different name"
> dataset.valid?
=> true
> dataset.update
=> #, @messages={}, @details={}>, @persisted=true, @previously_changed={}, @validation_context=nil>```
It will again reflect its persisted state:
```
dataset.persisted?
=> true
```Add legends to csv datasets with a properly formatted object.
```
a.legend = {"lat"=>"latitude", "date"=>["ISO", "dates", "here"], "long"=>"longitude", "region"=>["regions", "here"], "country"=>["ESP"]}
```
Create a /de novo/ dataset:```
a = APISdk::Dataset.new(
:name => "Example dataset",
:connector_type => "document",
:provider => "csv",
:application => ["rw"],
:connector_url => "",
:subtitle => "subtitulo",
:legend => {
"lat" => "latitude",
"long" => "longitude"
}
)a.token = "A proper CT API JWT"
a.create
```TODO: refactoring, creating of _de novo_ datasets, destroying, adding fields