stratumn_sdk 0.0.1 → 0.1.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: eb3eee12791c77b0f6419290a6e86932b6d3062a
4
- data.tar.gz: e1508ba9ea5e2936359488146e4cbe5fdca748dc
3
+ metadata.gz: 6d2abf779f1c0a8fcad745acab0014ea92a5b4e7
4
+ data.tar.gz: f9dd2942de0d88d5d7ca5da57e940e4169488224
5
5
  SHA512:
6
- metadata.gz: 32896b423d268bfcae34ce7a01fbe5d432efaf001f1ae32b0bffbe52fa18fff57f54cb518dd0342ccea1b45e8fbd5421965d1c3fb3cf4a22420363b2db37d037
7
- data.tar.gz: d69042a394cc1cbd4d3c08ef34bbcb7d3a3a8da65140c82bf72c6f8c0ed6488eb46e2765ed2e17148752a433cc08842bc50cd2eb9f98b27bf07eb64dc2ca3adc
6
+ metadata.gz: 015046b2b340eec30585a45d9d1c55e9686f741923b251ae865086dd5242e30ef1b67697fcf21753a3b17a11d04da0a6538f1c5f403e84afb4f1a8e458acca68
7
+ data.tar.gz: 18f15da26bb9ba77c65dd5ee5c7f9f6f58ac33b20f13bdc92018ab753687315e9ff765eea7e58c29ed6493886522c613bc9150925bb998f0345658c0c3a964bf
data/.gitignore CHANGED
@@ -1 +1 @@
1
- doc
1
+ pkg
data/.travis.yml CHANGED
@@ -3,3 +3,6 @@ language: ruby
3
3
  rvm:
4
4
  - 2.3.0
5
5
  - 2.2
6
+ script:
7
+ - bundle exec rake spec
8
+ - bundle exec rake rubocop
data/Gemfile.lock CHANGED
@@ -1,13 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stratumn_sdk (0.0.1)
4
+ stratumn_sdk (0.1.0)
5
5
  http (~> 2.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  addressable (2.4.0)
11
+ ast (2.3.0)
11
12
  crack (0.4.3)
12
13
  safe_yaml (~> 1.0.0)
13
14
  diff-lcs (1.2.5)
@@ -23,6 +24,10 @@ GEM
23
24
  domain_name (~> 0.5)
24
25
  http-form_data (1.0.1)
25
26
  http_parser.rb (0.6.0)
27
+ parser (2.3.1.2)
28
+ ast (~> 2.2)
29
+ powerpack (0.1.1)
30
+ rainbow (2.0.0)
26
31
  rake (10.5.0)
27
32
  rspec (3.5.0)
28
33
  rspec-core (~> 3.5.0)
@@ -37,10 +42,18 @@ GEM
37
42
  diff-lcs (>= 1.2.0, < 2.0)
38
43
  rspec-support (~> 3.5.0)
39
44
  rspec-support (3.5.0)
45
+ rubocop (0.42.0)
46
+ parser (>= 2.3.1.1, < 3.0)
47
+ powerpack (~> 0.1)
48
+ rainbow (>= 1.99.1, < 3.0)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (~> 1.0, >= 1.0.1)
51
+ ruby-progressbar (1.7.5)
40
52
  safe_yaml (1.0.4)
41
53
  unf (0.1.4)
42
54
  unf_ext
43
55
  unf_ext (0.0.7.2)
56
+ unicode-display_width (1.1.0)
44
57
  vcr (3.0.3)
45
58
  webmock (2.1.0)
46
59
  addressable (>= 2.3.6)
@@ -54,6 +67,7 @@ DEPENDENCIES
54
67
  bundler (~> 1.12)
55
68
  rake (~> 10.0)
56
69
  rspec (~> 3.0)
70
+ rubocop (~> 0.42)
57
71
  stratumn_sdk!
58
72
  vcr (~> 3.0)
59
73
  webmock (~> 2.1)
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Stratumn SDK for Ruby
2
2
 
3
3
  [![build status](https://travis-ci.org/stratumn/stratumn-sdk-ruby.svg?branch=master)](https://travis-ci.org/stratumn/stratumn-sdk-ruby.svg?branch=master)
4
+ [![Gem Version](https://badge.fury.io/rb/stratumn_sdk.svg)](https://badge.fury.io/rb/stratumn_sdk)
4
5
 
5
6
  Interact with your Stratumn agent from your ruby application
6
7
 
@@ -121,6 +122,9 @@ Executes a transition function and returns the new link.
121
122
  application = StratumnSdk::Application.load('quickstart')
122
123
  link = application.get_link('aee5427')
123
124
  new_link = link.addMessage('Hello, World!')
125
+
126
+ # underscore version is also available
127
+ new_link = link.add_message('Hello, World!')
124
128
  ```
125
129
 
126
130
  ## Development
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "stratumn_sdk"
3
+ require 'bundler/setup'
4
+ require 'stratumn_sdk'
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.
@@ -10,5 +10,5 @@ require "stratumn_sdk"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -1,4 +1,6 @@
1
1
  module StratumnSdk
2
+ ##
3
+ # Represents a Stratumn application
2
4
  class Application
3
5
  include Request
4
6
  extend Request
@@ -6,10 +8,14 @@ module StratumnSdk
6
8
  attr_accessor :url, :id, :name, :agent_info
7
9
 
8
10
  def self.load(application_name, application_location = nil)
9
- url = application_location || StratumnSdk.config[:application_url].gsub('%s', application_name)
11
+ url = application_location ||
12
+ StratumnSdk.config[:application_url].gsub('%s', application_name)
10
13
  attributes = get(url)
11
14
 
12
- self.new(url, attributes['id'], attributes['name'], attributes['agentInfo'])
15
+ new(url,
16
+ attributes['id'],
17
+ attributes['name'],
18
+ attributes['agentInfo'])
13
19
  end
14
20
 
15
21
  def initialize(url, id, name, agent_info)
@@ -0,0 +1,13 @@
1
+ module StratumnSdk
2
+ # We would like to avoid depending on ActiveSupport
3
+ module Helper
4
+ def underscore(string)
5
+ word = string.to_s.dup
6
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
7
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
8
+ word.tr!('-', '_')
9
+ word.downcase!
10
+ word
11
+ end
12
+ end
13
+ end
@@ -1,6 +1,9 @@
1
1
  module StratumnSdk
2
+ ##
3
+ # Represents a link in a Stratumn application
2
4
  class Link
3
5
  include Request
6
+ include Helper
4
7
 
5
8
  attr_accessor :application, :meta, :state, :link, :linkHash
6
9
 
@@ -13,14 +16,7 @@ module StratumnSdk
13
16
  self.linkHash = obj['meta']['linkHash']
14
17
 
15
18
  application.agent_info['functions'].each do |(method, _)|
16
- define_singleton_method(method) do |*args|
17
-
18
- url = "#{application.url}/links/#{linkHash}/#{method}"
19
-
20
- result = post(url, json: args)
21
-
22
- Link.new(application, result)
23
- end
19
+ add_transition_method(method)
24
20
  end
25
21
  end
26
22
 
@@ -39,9 +35,26 @@ module StratumnSdk
39
35
  def self.load(segment)
40
36
  meta = segment['meta']
41
37
 
42
- application = Application.load(meta['application'], meta['applicationLocation'])
38
+ application = Application.load(
39
+ meta['application'],
40
+ meta['applicationLocation']
41
+ )
43
42
 
44
43
  application.get_link(meta['linkHash'])
45
44
  end
45
+
46
+ private
47
+
48
+ def add_transition_method(method)
49
+ define_singleton_method(method) do |*args|
50
+ url = "#{application.url}/links/#{linkHash}/#{method}"
51
+
52
+ result = post(url, json: args)
53
+
54
+ self.class.new(application, result)
55
+ end
56
+
57
+ singleton_class.send(:alias_method, underscore(method), method)
58
+ end
46
59
  end
47
60
  end
@@ -1,8 +1,9 @@
1
1
  require 'http'
2
2
 
3
3
  module StratumnSdk
4
+ ##
5
+ # Wrapper around HTTP.request that parses the response and raises on error
4
6
  module Request
5
-
6
7
  def get(*args)
7
8
  request(:get, *args)
8
9
  end
@@ -10,18 +11,21 @@ module StratumnSdk
10
11
  def post(*args)
11
12
  result = request(:post, *args)
12
13
 
13
- raise result['meta']['errorMessage'] if result['meta'] && result['meta']['errorMessage']
14
+ if result['meta'] && result['meta']['errorMessage']
15
+ raise result['meta']['errorMessage']
16
+ end
14
17
 
15
18
  result
16
19
  end
17
20
 
18
21
  private
19
- def request(verb, *args)
20
- result = HTTP.request(verb, *args).parse
21
22
 
22
- raise result['error'] if result.is_a?(Hash) && result['error']
23
+ def request(verb, *args)
24
+ result = HTTP.request(verb, *args).parse
23
25
 
24
- result
25
- end
26
+ raise result['error'] if result.is_a?(Hash) && result['error']
27
+
28
+ result
29
+ end
26
30
  end
27
31
  end
@@ -1,3 +1,3 @@
1
1
  module StratumnSdk
2
- VERSION = "0.0.1"
2
+ VERSION = '0.1.0'.freeze
3
3
  end
data/lib/stratumn_sdk.rb CHANGED
@@ -1,33 +1,39 @@
1
1
  require 'stratumn_sdk/version'
2
2
  require 'stratumn_sdk/request'
3
+ require 'stratumn_sdk/helper'
3
4
  require 'stratumn_sdk/application'
4
5
  require 'stratumn_sdk/link'
5
6
 
6
7
  require 'yaml'
7
8
 
9
+ ##
10
+ # Allows interacting with your Stratumn agent from your ruby app
8
11
  module StratumnSdk
9
-
10
12
  # Configuration defaults
11
13
  @config = {
12
- base_url: 'https://stratumn.rocks',
13
- application_url: 'https://%s.stratumn.rocks'
14
- }
14
+ base_url: 'https://stratumn.rocks',
15
+ application_url: 'https://%s.stratumn.rocks'
16
+ }
15
17
 
16
18
  @valid_config_keys = @config.keys
17
19
 
18
20
  # Configure through hash
19
21
  def self.configure(opts = {})
20
- opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
22
+ opts.each do |k, v|
23
+ @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym
24
+ end
21
25
  end
22
26
 
23
27
  # Configure through yaml file
24
28
  def self.configure_with(path_to_yaml_file)
25
29
  begin
26
- config = YAML::load(IO.read(path_to_yaml_file))
30
+ config = YAML.load(IO.read(path_to_yaml_file))
27
31
  rescue Errno::ENOENT
28
- log(:warning, "YAML configuration file couldn't be found. Using defaults."); return
32
+ puts 'YAML configuration file couldn\'t be found. Using defaults.'
33
+ return
29
34
  rescue Psych::SyntaxError
30
- log(:warning, "YAML configuration file contains invalid syntax. Using defaults."); return
35
+ puts 'YAML configuration file contains invalid syntax. Using defaults.'
36
+ return
31
37
  end
32
38
 
33
39
  configure(config)
data/stratumn_sdk.gemspec CHANGED
@@ -4,26 +4,28 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'stratumn_sdk/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "stratumn_sdk"
7
+ spec.name = 'stratumn_sdk'
8
8
  spec.version = StratumnSdk::VERSION
9
- spec.authors = ["Stratumn Team"]
10
- spec.email = ["stratumn@gmail.com"]
9
+ spec.authors = ['Stratumn Team']
10
+ spec.email = ['stratumn@gmail.com']
11
11
 
12
- spec.summary = %q{Interact with your Stratumn agent from your ruby application}
13
- spec.homepage = "https://github.com/stratumn/stratumn-sdk-ruby"
14
- spec.license = "MIT"
12
+ spec.summary = 'Interact with your Stratumn agent from your ruby app'
13
+ spec.homepage = 'https://github.com/stratumn/stratumn-sdk-ruby'
14
+ spec.license = 'MIT'
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.bindir = "exe"
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
18
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
- spec.require_paths = ["lib"]
21
+ spec.require_paths = ['lib']
20
22
 
21
- spec.add_development_dependency "bundler", "~> 1.12"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "rspec", "~> 3.0"
24
- spec.add_development_dependency "vcr", "~> 3.0"
25
- spec.add_development_dependency "webmock", "~> 2.1"
23
+ spec.add_development_dependency 'bundler', '~> 1.12'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+ spec.add_development_dependency 'vcr', '~> 3.0'
27
+ spec.add_development_dependency 'webmock', '~> 2.1'
28
+ spec.add_development_dependency 'rubocop', '~> 0.42'
26
29
 
27
- spec.add_runtime_dependency "http", '~> 2.0'
30
+ spec.add_runtime_dependency 'http', '~> 2.0'
28
31
  end
29
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stratumn_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stratumn Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-11 00:00:00.000000000 Z
11
+ date: 2016-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.42'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.42'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: http
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +128,7 @@ files:
114
128
  - bin/setup
115
129
  - lib/stratumn_sdk.rb
116
130
  - lib/stratumn_sdk/application.rb
131
+ - lib/stratumn_sdk/helper.rb
117
132
  - lib/stratumn_sdk/link.rb
118
133
  - lib/stratumn_sdk/request.rb
119
134
  - lib/stratumn_sdk/version.rb
@@ -138,8 +153,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
153
  version: '0'
139
154
  requirements: []
140
155
  rubyforge_project:
141
- rubygems_version: 2.4.8
156
+ rubygems_version: 2.4.6
142
157
  signing_key:
143
158
  specification_version: 4
144
- summary: Interact with your Stratumn agent from your ruby application
159
+ summary: Interact with your Stratumn agent from your ruby app
145
160
  test_files: []