blueprint-api-rails 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6502d011050b9786945a3f1f925f51af9f3f96f3
4
+ data.tar.gz: 7f95f1e4053abdc6a68d8df469ae23e235fda945
5
+ SHA512:
6
+ metadata.gz: 784268e1cdd598b43525d24924fd3cce843576a226b9e09e136f27768c6677eb721b20a97e535ef59ba9e97f9e177dc01cae3da7a6e96fa377bf136b4a0eb5ae
7
+ data.tar.gz: ec52444c33f3ef868f5b4df5be9e95ccda3c2bddef8e19e9458e796b5131cd3a5ca2cb9c97a6233fe75ecadac5de54a67414cf1784061b512ea40f3939cf699c
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # Ignore IDE-specific files
12
+ .idea
data/.idea/.name ADDED
@@ -0,0 +1 @@
1
+ blueprint-api-rails
data/.idea/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build blueprint-api-rails-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Build and install blueprint-api-rails-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeTask description="Create tag v0.1.0 and build and push blueprint-api-rails-0.1.0.gem to Rubygems" fullCmd="release" taksId="release" /></RakeGroup></Settings>
@@ -0,0 +1,42 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="FacetManager">
4
+ <facet type="gem" name="Ruby Gem">
5
+ <configuration>
6
+ <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
7
+ <option name="GEM_APP_TEST_PATH" value="" />
8
+ <option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
9
+ </configuration>
10
+ </facet>
11
+ </component>
12
+ <component name="ModuleRunConfigurationManager">
13
+ <configuration default="false" name="rails" type="RubyRunConfigurationType" factoryName="Ruby" temporary="true">
14
+ <module name="blueprint-api-rails" />
15
+ <RUBY_RUN_CONFIG NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
16
+ <RUBY_RUN_CONFIG NAME="WORK DIR" VALUE="$MODULE_DIR$/lib/blueprint/api" />
17
+ <RUBY_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
18
+ <RUBY_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
19
+ <RUBY_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
20
+ <envs />
21
+ <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
22
+ <EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
23
+ <EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
24
+ <COVERAGE_PATTERN ENABLED="true">
25
+ <PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
26
+ </COVERAGE_PATTERN>
27
+ </EXTENSION>
28
+ <RUBY_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="$MODULE_DIR$/lib/blueprint/api/rails.rb" />
29
+ <RUBY_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="" />
30
+ <method />
31
+ </configuration>
32
+ </component>
33
+ <component name="NewModuleRootManager">
34
+ <content url="file://$MODULE_DIR$">
35
+ <excludeFolder url="file://$MODULE_DIR$/.bundle" />
36
+ <excludeFolder url="file://$MODULE_DIR$/vendor/bundle" />
37
+ </content>
38
+ <orderEntry type="inheritedJdk" />
39
+ <orderEntry type="sourceFolder" forTests="false" />
40
+ <orderEntry type="library" scope="PROVIDED" name="rake (v10.3.2, rbenv: 2.1.1) [gem]" level="application" />
41
+ </component>
42
+ </module>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding">
4
+ <file url="PROJECT" charset="UTF-8" />
5
+ </component>
6
+ </project>
data/.idea/misc.xml ADDED
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectLevelVcsManager" settingsEditedManually="false">
4
+ <OptionsSetting value="true" id="Add" />
5
+ <OptionsSetting value="true" id="Remove" />
6
+ <OptionsSetting value="true" id="Checkout" />
7
+ <OptionsSetting value="true" id="Update" />
8
+ <OptionsSetting value="true" id="Status" />
9
+ <OptionsSetting value="true" id="Edit" />
10
+ <ConfirmationsSetting value="0" id="Add" />
11
+ <ConfirmationsSetting value="0" id="Remove" />
12
+ </component>
13
+ <component name="ProjectRootManager" version="2" project-jdk-name="rbenv: 2.1.1" project-jdk-type="RUBY_SDK" />
14
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/blueprint-api-rails.iml" filepath="$PROJECT_DIR$/.idea/blueprint-api-rails.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in blueprint-api-rails.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Blueprint::Api::Rails
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/blueprint/api/rails`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'blueprint-api-rails'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install blueprint-api-rails
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/blueprint-api-rails.
36
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "blueprint/api/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'blueprint/api/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'blueprint-api-rails'
8
+ spec.version = Blueprint::Api::Rails::VERSION
9
+ spec.authors = ['benjii']
10
+ spec.email = ['ben.deany@gmail.com']
11
+
12
+ spec.summary = %q{Rails client for the Anaxim Blueprint API}
13
+ spec.homepage = 'http://anaxim.io'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = 'exe'
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.10'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ spec.add_runtime_dependency 'faraday', '~> 0.9.2'
23
+ end
@@ -0,0 +1,7 @@
1
+ module Blueprint
2
+ module Api
3
+ module Rails
4
+ VERSION = '0.1.2'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,221 @@
1
+ require 'blueprint/api/rails/version'
2
+ require 'faraday'
3
+
4
+ module Blueprint
5
+
6
+ BLUEPRINT_SERVER = ENV['BLUEPRINT_SERVER'] || 'http://anaxim.io'
7
+ BLUEPRINT_URL_CONTEXT = '/api/v1/events'
8
+
9
+
10
+ STRUCTURE_NEW = 'start'
11
+ MESSAGE = 'message'
12
+ CLASSIFIER_NEW = 'classifier-new'
13
+
14
+ # allow users to set the API key
15
+ def self.set_api_key api_key
16
+ @api_key = api_key
17
+ end
18
+
19
+ # call this to create a structure and get a design context
20
+ def self.start(structure_id, name)
21
+ DesignContext.new(@api_key, structure_id).send STRUCTURE_NEW, { :name => name }
22
+ end
23
+
24
+
25
+ class DesignContext
26
+
27
+ def initialize(api_key, structure_id)
28
+ @api_key = api_key
29
+ @structure_id = structure_id
30
+ @branch = `git rev-parse --abbrev-ref HEAD 2>&1`.strip! || 'master'
31
+
32
+ # initialise faraday
33
+ @conn = Faraday.new(:url => BLUEPRINT_SERVER) do |faraday|
34
+ faraday.response :logger # log requests to STDOUT
35
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
36
+ end
37
+ end
38
+
39
+ # creates a design context between source and target
40
+ def link(source, target)
41
+ LinkDesignContext.new(@api_key, @structure_id, source, target)
42
+ end
43
+
44
+ # creates a new message classifier
45
+ def classifier(from, condition, to)
46
+ self.send CLASSIFIER_NEW,
47
+ {
48
+ :from => from,
49
+ :condition => condition,
50
+ :to => to
51
+ }
52
+ nil
53
+ end
54
+
55
+ # logs a message between two nodes in the structure
56
+ def log(source, target, type, message = { }, extras = { })
57
+ self.send MESSAGE,
58
+ {
59
+ :source => source,
60
+ :target => target
61
+ },
62
+ {
63
+ :type => type,
64
+ :payload => {
65
+ :message => message, # the message that was sent
66
+ :extras => extras # extra details about the message that can aid classification
67
+ }
68
+ }
69
+ nil
70
+ end
71
+
72
+ # utility method for sending JSON payloads to the Anaxim servers - should never be called directly
73
+ def send(event_type, properties = { }, message = { })
74
+
75
+ # construct the base payload
76
+ payload = {
77
+ :header => {
78
+ :structure_id => @structure_id,
79
+ :properties => properties,
80
+ :branch => {
81
+ :name => @branch || 'master'
82
+ },
83
+ :eventType => event_type
84
+ }
85
+ }
86
+
87
+ # merge (append) the properties hash onto the payload (properties vary per event type)
88
+ payload.merge! message
89
+
90
+ @conn.post do |req|
91
+ req.url BLUEPRINT_URL_CONTEXT
92
+ req.headers['Content-Type'] = 'application/json'
93
+ req.headers['X-Api-Key'] = @api_key
94
+ req.body = payload.to_json
95
+ end
96
+
97
+ self
98
+ end
99
+
100
+ end
101
+
102
+ class LinkDesignContext < DesignContext
103
+
104
+ def initialize(api_key, structure_id, source, target)
105
+ @api_key = api_key
106
+ @structure_id = structure_id
107
+ @source = source
108
+ @target = target
109
+ @branch = `git rev-parse --abbrev-ref HEAD 2>&1`.strip! || 'master'
110
+
111
+ # initialise faraday
112
+ @conn = Faraday.new(:url => BLUEPRINT_SERVER) do |faraday|
113
+ faraday.response :logger # log requests to STDOUT
114
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
115
+ end
116
+ end
117
+
118
+ # logs a message between two nodes in the structure
119
+ def log(type, message = { }, extras = { })
120
+ self.send MESSAGE,
121
+ {
122
+ :source => @source,
123
+ :target => @target
124
+
125
+ },
126
+ {
127
+ :type => type,
128
+ :payload => {
129
+ :message => message, # the message that was sent
130
+ :extras => extras # extra details about the message that can aid classification
131
+ }
132
+ }
133
+ nil
134
+ end
135
+
136
+ end
137
+
138
+ end
139
+
140
+
141
+ # # activity diagram event types
142
+ # ACTIVITY_START = 'activity-start'
143
+ # ACTIVITY_ACTION = 'activity-action'
144
+ # ACTIVITY_DECISION = 'activity-decision'
145
+ # ACTIVITY_DECISION_OUTCOME = 'activity-decision-outcome'
146
+ # ACTIVITY_OUTCOME = 'activity-outcome'
147
+ # ACTIVITY_END = 'activity-end'
148
+
149
+ # COMPONENTS_START = 'components-start'
150
+ # COMPONENTS_NEW = 'components-new'
151
+ # COMPONENTS_LINK = 'components-link'
152
+ #
153
+ # MESSAGE = 'message'
154
+
155
+
156
+ # # use this to create a new activity - returns a design context, which can be used for subsequent calls
157
+ # def self.start_activity(diagram, name, start_state)
158
+ # DesignContext.new(@api_key, diagram).send ACTIVITY_START, { :name => name, :state => start_state }
159
+ # end
160
+
161
+ # # use this to create a new set of system components - returns a design context, which can be used for subsequent calls
162
+ # def self.declare_system(diagram, name)
163
+ # DesignContext.new(@api_key, diagram).send COMPONENTS_START, { :name => name }
164
+ # end
165
+
166
+ # def self.log_message(diagram, identifier, type, message = { })
167
+ # DesignContext.new(@api_key, diagram, identifier, nil)
168
+ # .send MESSAGE, { :type => type, :message => message }
169
+ # nil
170
+ # end
171
+
172
+
173
+
174
+ # # -----------------------------------------------------------------------
175
+ # # activity diagram API calls
176
+ #
177
+ # def decide(identifier, condition)
178
+ # # returns a new design context that represents the decision
179
+ # DesignContext.new(@api_key, @diagram, identifier, self)
180
+ # .send ACTIVITY_DECISION, { :condition => condition }
181
+ # end
182
+ #
183
+ # def positive(*args)
184
+ # if args.length == 1
185
+ # outcome 'positive', args[0]
186
+ # elsif args.length == 2
187
+ # decision_outcome args[0], 'positive', args[1]
188
+ # end
189
+ # end
190
+ #
191
+ # def negative(*args)
192
+ # if args.length == 1
193
+ # outcome 'negative', args[0]
194
+ # elsif args.length == 2
195
+ # decision_outcome args[0], 'negative', args[1]
196
+ # end
197
+ # end
198
+ #
199
+ # def decision_outcome(identifier, outcome, condition)
200
+ # # returns a new design context that represents the outcome
201
+ # DesignContext.new(@api_key, @diagram, identifier, self)
202
+ # .send ACTIVITY_DECISION_OUTCOME, { :outcome => outcome, :condition => condition }
203
+ # end
204
+ #
205
+ # def outcome(outcome, action)
206
+ # # returns a new design context that represents the outcome
207
+ # DesignContext.new(@api_key, @diagram, nil, self)
208
+ # .send ACTIVITY_OUTCOME, { :outcome => outcome, :action => action }
209
+ # end
210
+ #
211
+ # def action(identifier, action)
212
+ # # returns a new design context that represents the action
213
+ # DesignContext.new(@api_key, @diagram, identifier, self)
214
+ # .send ACTIVITY_ACTION, { :action => action }
215
+ # end
216
+ #
217
+ # def end(state)
218
+ # # returns a new design context that represents the end of the activity
219
+ # DesignContext.new(@api_key, @diagram, nil, self)
220
+ # .send ACTIVITY_END, { :state => state }
221
+ # end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blueprint-api-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - benjii
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.2
55
+ description:
56
+ email:
57
+ - ben.deany@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".idea/.name"
64
+ - ".idea/.rakeTasks"
65
+ - ".idea/blueprint-api-rails.iml"
66
+ - ".idea/encodings.xml"
67
+ - ".idea/misc.xml"
68
+ - ".idea/modules.xml"
69
+ - ".idea/vcs.xml"
70
+ - ".travis.yml"
71
+ - Gemfile
72
+ - README.md
73
+ - Rakefile
74
+ - bin/console
75
+ - bin/setup
76
+ - blueprint-api-rails.gemspec
77
+ - lib/blueprint/api/rails.rb
78
+ - lib/blueprint/api/rails/version.rb
79
+ homepage: http://anaxim.io
80
+ licenses: []
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.8
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Rails client for the Anaxim Blueprint API
102
+ test_files: []