Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bettyblocks/betty_resource
Map BettyBlocks application resources to Ruby objects
https://github.com/bettyblocks/betty_resource
Last synced: about 2 months ago
JSON representation
Map BettyBlocks application resources to Ruby objects
- Host: GitHub
- URL: https://github.com/bettyblocks/betty_resource
- Owner: bettyblocks
- License: mit
- Created: 2013-01-22T19:50:58.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2016-12-19T12:39:01.000Z (about 8 years ago)
- Last Synced: 2024-03-26T23:54:21.652Z (10 months ago)
- Language: Ruby
- Size: 123 KB
- Stars: 2
- Watchers: 14
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.rdoc
- License: LICENSE
Awesome Lists containing this project
README
[![Code Climate](https://codeclimate.com/github/bettyblocks/betty_resource.png)](https://codeclimate.com/github/bettyblocks/betty_resource)
# BettyResource
Map Betty5 application resources to Ruby objects through the JSON API!
## Introduction
This gem is created to map resources directly to the Betty5 API with ease. Just include the gem in your Gemfile, configure the Betty5 API credentials and you're good to go!
## Installation
### Add `BettyResource` to your Gemfile
gem "betty_resource"
### Install the gem dependencies
$ bundle
### Configure the Betty5 API credentials
At first, you will need to create a user within the Betty5 application provided with an `api_password`. Ask one of the BettyBlocks developers for more information.
Afterwards, add the following in a Ruby file which gets required at startup of the application (e.g. within an `initializer`).
BettyResource.configure do |config|
config.host = "https://.bettyblocks.com"
config.user =
config.password =
end## Usage
Using `BettyResource` is pretty straightforward. Let's say you want to load, edit and save a record of the `Relation` model with ID 1:
$ relation = BettyResource::Relation.get 1
$ relation.first_name = "Paul"
$ relation.save #=> true## Using the console
The BettyResource repo is provided with `script/console` which you can use for development / testing purposes.
Run the following command in your console:
$ script/console
Loading BettyResource development environment
Configured connection
[1] pry(main)> r = BettyResource::Relation.get 1
=> #
[2] pry(main)> r.dirty?
=> false
[3] pry(main)> r.first_name = "Paul"
=> "Paul"
[4] pry(main)> r.dirty?
=> true
[5] pry(main)> r.changes
=> {"first_name"=>["Daniel", "Paul"]}
[6] pry(main)> r.first_name_changed?
=> true
[7] pry(main)> r.first_name_change
=> ["Daniel", "Paul"]
[8] pry(main)> r.first_name_was
=> "Daniel"
[9] pry(main)> r.save
=> true
[10] pry(main)> r.dirty?
=> false
[11] pry(main)> BettyResource::Relation.get(r.id).first_name
=> "Paul"## Testing
Run the following command for testing:
$ rake
You can also run a single test:
$ ruby test/unit/model/test_record.rb
## TODO
* Typecasting of attributes
## Contact us
For support, remarks and requests, please mail us at [[email protected]](mailto:[email protected]).
## License
Copyright (c) 2013 BettyBlocks B.V.
[http://bettyblocks.com](http://bettyblocks.com) - [[email protected]](mailto:[email protected])