README.md in stratumn_sdk-0.2.0 vs README.md in stratumn_sdk-1.0.0

- old
+ new

@@ -1,17 +1,17 @@ -# Stratumn SDK for Ruby +# Stratumn SDK for Ruby [ALPHA - incompatible with production] [![build status](https://travis-ci.org/stratumn/stratumn-sdk-ruby.svg?branch=master)](https://travis-ci.org/stratumn/stratumn-sdk-ruby.svg?branch=master) [![Gem Version](https://badge.fury.io/rb/stratumn_sdk.svg)](https://badge.fury.io/rb/stratumn_sdk) -Interact with your Stratumn agent from your ruby application +Interact with your Stratumn agent from your ruby agent code :: https://github.com/stratumn/stratumn-sdk-ruby ## Installation -Add this line to your application's Gemfile: +Add this line to your agent's Gemfile: ```ruby gem 'stratumn-sdk' ``` @@ -24,116 +24,127 @@ $ gem install stratumn-sdk ## Quickstart ```ruby -application = StratumnSdk::Application.load('quickstart') +agent = StratumnSdk::Agent.load('quickstart') -link = application.create_map('My message map') +segment = agent.create_map('My message map') -link = link.addMessage('Hello, World') +segment = segment.add_essage('Hello, World') -puts link.meta -puts link.state +puts segment.meta +puts segment.state ``` ## Reference -#### StratumnSdk::Application.load(name) +#### StratumnSdk::Agent.load(url) -Returns an instance of StratumnSdk::Application. +Returns an instance of StratumnSdk::Agent. ```ruby -application = StratumnSdk::Application.load('quickstart') -puts application.id +agent = StratumnSdk::Agent.load('http://localhost:3000') +puts agent.agent_info ``` -#### StratumnSdk::Application#create_map(*args) +#### StratumnSdk::Agent#create_map(*args) -Creates a new map in the application. +Creates a new map in the agent. ```ruby -application = StratumnSdk::Application.load('quickstart') -link = application.create_map('My message map') +agent = StratumnSdk::Agent.load('http://localhost:3000') +segment = agent.create_map('My message map') ``` -#### StratumnSdk::get_link(hash) +#### StratumnSdk::Agent.get_segment(hash) -Returns an existing link. +Returns an existing segment. ```ruby -application = StratumnSdk::Application.load('quickstart') -link = application.get_link('aee5427') -puts link.link_hash +agent = StratumnSdk::Agent.load('http://localhost:3000') +segment = agent.get_segment('aee5427') +puts segment.link_hash ``` -#### StratumnSdk::get_map(map_id, tags = []) +#### StratumnSdk::Agent.find_segments(options = {}) -Returns the links in a map, optionally filtered by tags. +Returns existing segments. -```ruby -application = StratumnSdk::Application.load('quickstart') -links = application.get_map('aee5427', ['tag1', 'tag2']) -``` +Available options are: -#### StratumnSdk::get_branches(hash, tags = []) +- `offset`: offset of first returned segments +- `limit`: limit number of returned segments +- `mapId`: return segments with specified map ID +- `prevLinkHash`: return segments with specified previous link hash +- `tags`: return segments that contains all the tags (array) -Returns he links whose previous hashes are the given hash, optionally filters by tags. - ```ruby -application = StratumnSdk::Application.load('quickstart') -links = application.get_branches('aee5427', ['tag1', 'tag2']) +agent = StratumnSdk::Agent.load('http://localhost:3000') +segments = agent.find_segments(tags: ['tag1', 'tag2']) ``` -#### StratumnSdk::Link#previous +#### StratumnSdk::Segment.from -Returns the previous link of a link (its parent). +Returns segment from a given raw object. ```ruby -application = StratumnSdk::Application.load('quickstart') -link = application.get_link('aee5427') -previous = link.previous +segment = StratumnSdk::Agent.from(raw_segment) +puts segment.agent +puts segment.link_hash ``` -#### StratumnSdk::Link#load +#### StratumnSdk::Segment#previous -Loads a full link. Can be useful when you only have the meta data of links. +Returns the previous segment of a segment (its parent). ```ruby -application = StratumnSdk::Application.load('quickstart') -links = application.get_branches('aee5427') - -links.map { |link| link.load } +agent = StratumnSdk::Agent.load('http://localhost:3000') +segment = agent.get_segment('aee5427') +previous = segment.previous ``` -#### StratumnSdk::Link#get_branches(tags) +#### StratumnSdk::Segment#load -Returns the links whose previous hashes are the hash of the link, optionally filters by tags. +Loads a full segment. Can be useful when you only have the meta data of links. ```ruby -application = StratumnSdk::Application.load('quickstart') -link = application.get_link('aee5427') -link.get_branches(['tag1']) +agent = StratumnSdk::Agent.load('http://localhost:3000') +segments = agent.find_segments + +segments.map { |segment| segment.load } ``` -#### StratumnSdk::Link#transition_function(*args) +#### StratumnSdk::Segment#transition_function(*args) -Executes a transition function and returns the new link. +Executes a transition function and returns the new segment. ```ruby -application = StratumnSdk::Application.load('quickstart') -link = application.get_link('aee5427') -new_link = link.addMessage('Hello, World!') +agent = StratumnSdk::Agent.load('http://localhost:3000') +segment = agent.get_segment('aee5427') +new_segment = segment.addMessage('Hello, World!') # underscore version is also available -new_link = link.add_message('Hello, World!') +new_segment = segment.add_message('Hello, World!') ``` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). + +## Tests + +Tests are run against a mock agent whose results are recorded by vcr. +Should you need to regenerate the cassettes or add new tests, the mock agent can be launched on port 3333. + +``` +$ cd spec/agent +$ npm install +$ node index.js +``` + ## License: (The MIT License)