stratumn_agent_client 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b54b413a5421c8b91a0b4bbe410c076b740e8ec5
4
- data.tar.gz: b24c9d169294fc6636fa60db3abd307fc0a00e06
3
+ metadata.gz: 5dc1d9233eb9b69631fa998886084001f7115c6b
4
+ data.tar.gz: 8333c017990136820863e091cdd149ad266089e2
5
5
  SHA512:
6
- metadata.gz: 38484bf60b05fe23bd7a5209f90254cc0a9af2ccbcf2a04886bd992844bd53f20596251050c9a6d5bdcdd70a2532735d5a63f21b48b53799a262b0dd9ff588f0
7
- data.tar.gz: a91bd644ab5aae6e4ecd3859d14f03d6d1e15336a092c712488c9512b6dc7c9f4799111f04d4803bb8b7af710a63191752004947d128a456ad2eeaab1bb87be2
6
+ metadata.gz: 35b965f742d54ef11e3d8bbc271b614a5bcbd6678be280a228e8531dec875d89c4e49945efff7380f46f0423fc29a794a7d7a2060f5686e953a31b4d355e3242
7
+ data.tar.gz: bc5aae0dacdd99d19cd31ef34bae849568fcd5f49d5fb1e5acf378e0ba860e168a4bc3bcfe0c8a8637c3360c7fcc7e00c53bd44cffc7e7150019b8292aad67cf
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in stratumn_sdk.gemspec
3
+ # Specify your gem's dependencies in agent_client.gemspec
4
4
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stratumn_agent_client (0.2.0)
4
+ stratumn_agent_client (1.0.0)
5
5
  http (~> 2.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
- # Agent client for Ruby
1
+ # Agent client for Ruby [ALPHA - incompatible with production]
2
2
 
3
3
  [![build status](https://travis-ci.org/stratumn/agent-client-ruby.svg?branch=master)](https://travis-ci.org/stratumn/agent-client-ruby.svg?branch=master)
4
- [![Gem Version](https://badge.fury.io/rb/agent_client.svg)](https://badge.fury.io/rb/stratumn_sdk)
4
+ [![Gem Version](https://badge.fury.io/rb/agent_client.svg)](https://badge.fury.io/rb/stratumn_agent_client)
5
5
 
6
- Interact with your Stratumn agent from your ruby application
6
+ Interact with your Stratumn agent from your ruby agent
7
7
 
8
8
  code :: https://github.com/stratumn/agent-client-ruby
9
9
 
10
10
  ## Installation
11
11
 
12
- Add this line to your application's Gemfile:
12
+ Add this line to your agent's Gemfile:
13
13
 
14
14
  ```ruby
15
15
  gem 'agent-client'
@@ -26,110 +26,119 @@ Or install it yourself as:
26
26
  ## Quickstart
27
27
 
28
28
  ```ruby
29
- application = AgentClient::Application.load('quickstart')
29
+ agent = AgentClient::Agent.load('quickstart')
30
30
 
31
- link = application.create_map('My message map')
31
+ segment = agent.create_map('My message map')
32
32
 
33
- link = link.addMessage('Hello, World')
33
+ segment = segment.add_essage('Hello, World')
34
34
 
35
- puts link.meta
36
- puts link.state
35
+ puts segment.meta
36
+ puts segment.state
37
37
  ```
38
38
 
39
39
  ## Reference
40
40
 
41
- #### AgentClient::Application.load(name)
41
+ #### AgentClient::Agent.load(url)
42
42
 
43
- Returns an instance of AgentClient::Application.
43
+ Returns an instance of AgentClient::Agent.
44
44
 
45
45
  ```ruby
46
- application = AgentClient::Application.load('quickstart')
47
- puts application.id
46
+ agent = AgentClient::Agent.load('http://localhost:3000')
47
+ puts agent.agent_info
48
48
  ```
49
49
 
50
- #### AgentClient::Application#create_map(*args)
50
+ #### AgentClient::Agent#create_map(*args)
51
51
 
52
- Creates a new map in the application.
52
+ Creates a new map in the agent.
53
53
 
54
54
  ```ruby
55
- application = AgentClient::Application.load('quickstart')
56
- link = application.create_map('My message map')
55
+ agent = AgentClient::Agent.load('http://localhost:3000')
56
+ segment = agent.create_map('My message map')
57
57
  ```
58
58
 
59
- #### AgentClient::Application.get_link(hash)
59
+ #### AgentClient::Agent.get_segment(hash)
60
60
 
61
- Returns an existing link.
61
+ Returns an existing segment.
62
62
 
63
63
  ```ruby
64
- application = AgentClient::Application.load('quickstart')
65
- link = application.get_link('aee5427')
66
- puts link.link_hash
64
+ agent = AgentClient::Agent.load('http://localhost:3000')
65
+ segment = agent.get_segment('aee5427')
66
+ puts segment.link_hash
67
67
  ```
68
68
 
69
- #### AgentClient::Application.get_map(map_id, tags = [])
69
+ #### AgentClient::Agent.find_segments(options = {})
70
70
 
71
- Returns the links in a map, optionally filtered by tags.
71
+ Returns existing segments.
72
72
 
73
- ```ruby
74
- application = AgentClient::Application.load('quickstart')
75
- links = application.get_map('aee5427', ['tag1', 'tag2'])
76
- ```
77
-
78
- #### AgentClient::Application.get_branches(hash, tags = [])
79
-
80
- Returns he links whose previous hashes are the given hash, optionally filters by tags.
73
+ Available options are:
74
+ - `offset`: offset of first returned segments
75
+ - `limit`: limit number of returned segments
76
+ - `mapId`: return segments with specified map ID
77
+ - `prevLinkHash`: return segments with specified previous link hash
78
+ - `tags`: return segments that contains all the tags (array)
81
79
 
82
80
  ```ruby
83
- application = AgentClient::Application.load('quickstart')
84
- links = application.get_branches('aee5427', ['tag1', 'tag2'])
81
+ agent = AgentClient::Agent.load('http://localhost:3000')
82
+ segments = agent.find_segments(tags: ['tag1', 'tag2'])
85
83
  ```
86
84
 
87
- #### AgentClient::Link#previous
85
+ #### AgentClient::Segment.from
88
86
 
89
- Returns the previous link of a link (its parent).
87
+ Returns segment from a given raw object.
90
88
 
91
89
  ```ruby
92
- application = AgentClient::Application.load('quickstart')
93
- link = application.get_link('aee5427')
94
- previous = link.previous
90
+ segment = AgentClient::Agent.from(raw_segment)
91
+ puts segment.agent
92
+ puts segment.link_hash
95
93
  ```
96
94
 
97
- #### AgentClient::Link#load
95
+ #### AgentClient::Segment#previous
98
96
 
99
- Loads a full link. Can be useful when you only have the meta data of links.
97
+ Returns the previous segment of a segment (its parent).
100
98
 
101
99
  ```ruby
102
- application = AgentClient::Application.load('quickstart')
103
- links = application.get_branches('aee5427')
104
-
105
- links.map { |link| link.load }
100
+ agent = AgentClient::Agent.load('http://localhost:3000')
101
+ segment = agent.get_segment('aee5427')
102
+ previous = segment.previous
106
103
  ```
107
104
 
108
- #### AgentClient::Link#get_branches(tags)
105
+ #### AgentClient::Segment#load
109
106
 
110
- Returns the links whose previous hashes are the hash of the link, optionally filters by tags.
107
+ Loads a full segment. Can be useful when you only have the meta data of links.
111
108
 
112
109
  ```ruby
113
- application = AgentClient::Application.load('quickstart')
114
- link = application.get_link('aee5427')
115
- link.get_branches(['tag1'])
110
+ agent = AgentClient::Agent.load('http://localhost:3000')
111
+ segments = agent.find_segments
112
+
113
+ segments.map { |segment| segment.load }
116
114
  ```
117
115
 
118
- #### AgentClient::Link#transition_function(*args)
116
+ #### AgentClient::Segment#transition_function(*args)
119
117
 
120
- Executes a transition function and returns the new link.
118
+ Executes a transition function and returns the new segment.
121
119
 
122
120
  ```ruby
123
- application = AgentClient::Application.load('quickstart')
124
- link = application.get_link('aee5427')
125
- new_link = link.addMessage('Hello, World!')
121
+ agent = AgentClient::Agent.load('http://localhost:3000')
122
+ segment = agent.get_segment('aee5427')
123
+ new_segment = segment.addMessage('Hello, World!')
126
124
 
127
125
  # underscore version is also available
128
- new_link = link.add_message('Hello, World!')
126
+ new_segment = segment.add_message('Hello, World!')
129
127
  ```
130
128
 
131
129
  ## Development
132
130
 
133
131
  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.
134
132
 
135
- 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)
133
+ 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).
134
+
135
+ ## Tests
136
+
137
+ Tests are run against a mock agent whose results are recorded by vcr.
138
+ Should you need to regenerate the cassettes or add new tests, the mock agent can be launched on port 3333.
139
+
140
+ ```
141
+ $ cd spec/agent
142
+ $ npm install
143
+ $ node index.js
144
+ ```
data/agent_client.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.email = ['stratumn@gmail.com']
17
17
 
18
18
  spec.summary = 'Interact with your Stratumn agent from your ruby app'
19
- spec.homepage = 'https://github.com/stratumn/stratumn-sdk-ruby'
19
+ spec.homepage = 'https://github.com/stratumn/agent-client-ruby'
20
20
  spec.license = 'MPL-2.0'
21
21
 
22
22
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bundler/setup'
4
- require 'stratumn_sdk'
4
+ require 'agent_client'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -0,0 +1,54 @@
1
+ # Copyright (C) 2017 Stratumn SAS
2
+ #
3
+ # This Source Code Form is subject to the terms of the Mozilla Public
4
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+
7
+ module AgentClient
8
+ ##
9
+ # Represents a Stratumn agent
10
+ class Agent
11
+ include Request
12
+ extend Request
13
+
14
+ attr_accessor :url, :agent_info, :store_info
15
+
16
+ def self.load(url)
17
+ attributes = get(url)
18
+
19
+ new(url,
20
+ attributes['agentInfo'],
21
+ attributes['storeInfo'])
22
+ end
23
+
24
+ def initialize(url, agent_info, store_info)
25
+ self.url = url
26
+ self.agent_info = agent_info
27
+ self.store_info = store_info
28
+ end
29
+
30
+ def create_map(*args)
31
+ result = post(url + '/segments', json: args)
32
+
33
+ Segment.new(self, result)
34
+ end
35
+
36
+ def get_map_ids(options = {})
37
+ get(url + '/maps?' + URI.encode_www_form(options))
38
+ end
39
+
40
+ def find_segments(options = {})
41
+ result = get(url + '/segments?' + URI.encode_www_form(options))
42
+
43
+ result.map do |link|
44
+ Segment.new(self, link)
45
+ end
46
+ end
47
+
48
+ def get_segment(link_hash)
49
+ result = get(url + '/segments/' + link_hash)
50
+
51
+ Segment.new(self, result)
52
+ end
53
+ end
54
+ end
@@ -7,57 +7,52 @@
7
7
  module AgentClient
8
8
  ##
9
9
  # Represents a link in a Stratumn application
10
- class Link
10
+ class Segment
11
11
  include Request
12
12
  include Helper
13
13
 
14
- attr_accessor :application, :meta, :state, :link, :link_hash
14
+ attr_accessor :agent, :meta, :state, :link, :link_hash
15
15
 
16
- def initialize(application, obj)
17
- self.application = application
16
+ def initialize(agent, obj)
17
+ self.agent = agent
18
18
 
19
19
  self.link = obj['link']
20
20
  self.meta = link['meta']
21
21
  self.state = link['state']
22
22
  self.link_hash = obj['meta']['linkHash']
23
23
 
24
- application.agent_info['functions'].each do |(method, _)|
24
+ agent.agent_info['actions'].each do |(method, _)|
25
25
  add_transition_method(method)
26
26
  end
27
27
  end
28
28
 
29
29
  def previous
30
- application.get_link(meta['prevLinkHash']) if meta['prevLinkHash']
30
+ agent.get_segment(meta['prevLinkHash']) if meta['prevLinkHash']
31
31
  end
32
32
 
33
- def get_branches(tags)
34
- application.get_branches(link_hash, tags)
33
+ def find_segments(options = {})
34
+ agent.find_segments(options)
35
35
  end
36
36
 
37
37
  def load
38
- application.get_link(link_hash)
38
+ agent.get_segment(link_hash)
39
39
  end
40
40
 
41
- def self.load(segment)
42
- meta = segment['meta']
41
+ def self.from(segment)
42
+ agent = Agent.load(segment['meta']['agentUrl'])
43
43
 
44
- application = Application.load(
45
- meta['application'],
46
- meta['applicationLocation']
47
- )
48
-
49
- application.get_link(meta['linkHash'])
44
+ new(agent, segment)
50
45
  end
51
46
 
52
47
  private
53
48
 
54
49
  def add_transition_method(method)
55
50
  define_singleton_method(method) do |*args|
56
- url = "#{application.url}/links/#{link_hash}/#{method}"
51
+ url = "#{agent.url}/segments/#{link_hash}/#{method}"
57
52
 
58
53
  result = post(url, json: args)
59
54
 
60
- self.class.new(application, result)
55
+ self.class.new(agent, result)
61
56
  end
62
57
 
63
58
  singleton_class.send(:alias_method, underscore(method), method)
@@ -5,5 +5,5 @@
5
5
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
 
7
7
  module AgentClient
8
- VERSION = '0.2.0'.freeze
8
+ VERSION = '1.0.0'.freeze
9
9
  end
data/lib/agent_client.rb CHANGED
@@ -7,8 +7,8 @@
7
7
  require 'agent_client/version'
8
8
  require 'agent_client/request'
9
9
  require 'agent_client/helper'
10
- require 'agent_client/application'
11
- require 'agent_client/link'
10
+ require 'agent_client/agent'
11
+ require 'agent_client/segment'
12
12
 
13
13
  require 'yaml'
14
14
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stratumn_agent_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stratumn Team
@@ -128,12 +128,12 @@ files:
128
128
  - bin/console
129
129
  - bin/setup
130
130
  - lib/agent_client.rb
131
- - lib/agent_client/application.rb
131
+ - lib/agent_client/agent.rb
132
132
  - lib/agent_client/helper.rb
133
- - lib/agent_client/link.rb
134
133
  - lib/agent_client/request.rb
134
+ - lib/agent_client/segment.rb
135
135
  - lib/agent_client/version.rb
136
- homepage: https://github.com/stratumn/stratumn-sdk-ruby
136
+ homepage: https://github.com/stratumn/agent-client-ruby
137
137
  licenses:
138
138
  - MPL-2.0
139
139
  metadata: {}
@@ -1,66 +0,0 @@
1
- # Copyright (C) 2017 Stratumn SAS
2
- #
3
- # This Source Code Form is subject to the terms of the Mozilla Public
4
- # License, v. 2.0. If a copy of the MPL was not distributed with this
5
- # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
-
7
- module AgentClient
8
- ##
9
- # Represents a Stratumn application
10
- class Application
11
- include Request
12
- extend Request
13
-
14
- attr_accessor :url, :id, :name, :agent_info
15
-
16
- def self.load(application_name, application_location = nil)
17
- url = application_location ||
18
- AgentClient.config[:application_url].gsub('%s', application_name)
19
- attributes = get(url)
20
-
21
- new(url,
22
- attributes['id'],
23
- attributes['name'],
24
- attributes['agentInfo'])
25
- end
26
-
27
- def initialize(url, id, name, agent_info)
28
- self.url = url
29
- self.id = id
30
- self.name = name
31
- self.agent_info = agent_info
32
- end
33
-
34
- def create_map(*args)
35
- result = post(url + '/maps', json: args)
36
-
37
- Link.new(self, result)
38
- end
39
-
40
- def get_link(link_hash)
41
- result = get(url + '/links/' + link_hash)
42
-
43
- Link.new(self, result)
44
- end
45
-
46
- def get_map(map_id, tags = [])
47
- query = tags.empty? ? '' : "?tags=#{tags.join('&tags=')}"
48
-
49
- result = get(url + '/maps/' + map_id + query)
50
-
51
- result.map do |link|
52
- Link.new(self, link)
53
- end
54
- end
55
-
56
- def get_branches(link_hash, tags = [])
57
- query = tags.empty? ? '' : "?tags=#{tags.join('&tags=')}"
58
-
59
- result = get(url + '/branches/' + link_hash + query)
60
-
61
- result.map do |link|
62
- Link.new(self, link)
63
- end
64
- end
65
- end
66
- end