assemble 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a1675caa241454e5a914c07e1c99aa07f5b2361a
4
+ data.tar.gz: bb35c39ca35dc61ecb88ccec11aeb7d4de228816
5
+ SHA512:
6
+ metadata.gz: 1c2da7ac6ead78913db7363085a3a974b0ae869d921b21b50a0464b09461a0fd80a67f9bfb4376120b854633d4024ad7f7d21533278efb0578d9db5dec29049f
7
+ data.tar.gz: 27daf55fcb940026929c2af26615d5af94bbed2c78c5155dad469cc84b4826f745f491bbed68de48ace0dd8d106be0911b43ef980bc5ab4c62750d090b446632
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .assemble
24
+ .assemble.security
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'awesome_print'
6
+ gem 'guard-bundler'
7
+ gem 'guard-rspec'
8
+ gem 'pry-nav'
9
+
10
+ group :test do
11
+ gem 'rspec', '~> 3.0'
12
+ end
@@ -0,0 +1,12 @@
1
+ guard :bundler do
2
+ watch('Gemfile')
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard :rspec do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { "spec" }
9
+ watch(%r|^spec/{support,matchers}/(.+)\.rb$|) { "spec" }
10
+ watch('spec/spec_helper.rb') { "spec" }
11
+ end
12
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Josh Lane
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Rivet
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rivet'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rivet
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/rivet/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'assemble/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "assemble"
8
+ spec.version = Assemble::VERSION
9
+ spec.authors = ["Josh Lane"]
10
+ spec.email = ["me@joshualane.com"]
11
+ spec.summary = %q{Rally REST API Client}
12
+ spec.description = %q{Cistern-based client for Rally Dev}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "cistern", "~> 0.8"
25
+ spec.add_dependency "faraday", "~> 0.9"
26
+ spec.add_dependency "faraday_middleware", "~> 0.9"
27
+ spec.add_dependency "addressable"
28
+ end
@@ -0,0 +1,15 @@
1
+ require "assemble/version"
2
+
3
+ require 'addressable/uri'
4
+ require 'cistern'
5
+ require 'faraday'
6
+ require 'faraday_middleware'
7
+ require 'logger'
8
+
9
+ module Assemble
10
+ # Your code goes here...
11
+ end
12
+
13
+ require 'assemble/logger'
14
+ require 'assemble/response'
15
+ require 'assemble/client'
@@ -0,0 +1,121 @@
1
+ class Assemble::Client < Cistern::Service
2
+
3
+ model_path "assemble/models"
4
+ request_path "assemble/requests"
5
+
6
+ # tags
7
+ model :tag
8
+ collection :tags
9
+ request :create_tag
10
+ request :destroy_tag
11
+ request :get_tag
12
+ request :get_tags
13
+ request :update_tag
14
+
15
+ requires :token
16
+
17
+ recognizes :url, :adapter, :logger, :connection_options, :version
18
+
19
+ class Real
20
+ attr_reader :connection, :url
21
+
22
+ def initialize(options={})
23
+ base_url = options[:url] || ENV['RALLY_URL'] || "https://rally1.rallydev.com/slm/webservice/"
24
+ version = options[:version] || "v3.0"
25
+
26
+ @url = URI.parse(File.join(base_url, version))
27
+ logger = options[:logger] || Logger.new(nil)
28
+ @token = options[:token]
29
+
30
+ adapter = options[:adapter] || Faraday.default_adapter
31
+ connection_options = options[:connection_options] || {}
32
+
33
+ @connection = Faraday.new({url: @url}.merge(connection_options)) do |builder|
34
+ # response
35
+ builder.response :json
36
+
37
+ # request
38
+ builder.request :retry,
39
+ :max => 5,
40
+ :interval => 1,
41
+ :interval_randomness => 0.05,
42
+ :backoff_factor => 2
43
+ builder.request :multipart
44
+ builder.request :json
45
+
46
+ builder.use Assemble::Logger, logger
47
+
48
+ builder.adapter(*adapter)
49
+ end
50
+ end
51
+
52
+ def request(options={})
53
+ method = (options[:method] || "get").to_s.downcase.to_sym
54
+ url = Addressable::URI.parse(options[:url] || File.join(@url.to_s, options[:path] || "/"))
55
+ url.query_values = (url.query_values || {}).merge(options[:query] || {})
56
+ params = options[:params] || {}
57
+ body = options[:body]
58
+ headers = options[:headers] || {}
59
+
60
+ if body.nil? && !params.empty?
61
+ headers["Content-Type"] ||= "application/x-www-form-urlencoded"
62
+ end
63
+ headers.merge!("ZSESSIONID" => @token) if @token
64
+
65
+ # Authentication
66
+ params.merge!(key: @token)
67
+
68
+ response = self.connection.send(method) do |req|
69
+ req.url(url.to_s)
70
+ req.headers.merge!(headers)
71
+ req.params.merge!(params)
72
+ req.body = body
73
+ end
74
+
75
+ Assemble::Response.new(
76
+ :status => response.status,
77
+ :headers => response.headers,
78
+ :body => response.body,
79
+ :request => {
80
+ :method => method,
81
+ :url => url,
82
+ }
83
+ ).raise!
84
+ end
85
+ end # Real
86
+
87
+ class Mock
88
+
89
+ def self.data
90
+ @data ||= begin
91
+ {
92
+ :tags => {},
93
+ }
94
+ end
95
+ end
96
+
97
+ def response(options={})
98
+ url = options[:url] || File.join(@url.to_s, options[:path] || "/")
99
+ method = (options[:method] || :get).to_s.to_sym
100
+ status = options[:status] || 200
101
+ body = options[:body]
102
+ headers = {
103
+ "Content-Type" => "application/json; charset=utf-8"
104
+ }.merge(options[:headers] || {})
105
+
106
+ Assemble::Response.new(
107
+ :status => status,
108
+ :headers => headers,
109
+ :body => body,
110
+ :request => {
111
+ :method => method,
112
+ :url => url,
113
+ }
114
+ ).raise!
115
+ end
116
+
117
+ def url_for(path)
118
+ File.join(@url, path)
119
+ end
120
+ end # Mock
121
+ end # Assemble::Client
@@ -0,0 +1,30 @@
1
+ class Assemble::Logger < Faraday::Response::Middleware
2
+ extend Forwardable
3
+
4
+ def initialize(app, logger = nil)
5
+ super(app)
6
+ @logger = logger || ::Logger.new(nil)
7
+ end
8
+
9
+ def_delegators :@logger, :debug, :info, :warn, :error, :fatal
10
+
11
+ def call(env)
12
+ debug "REQUEST: #{env[:method].upcase} #{env[:url].to_s}"
13
+ debug('request') { dump_headers env[:request_headers] }
14
+ debug('request.body') { env[:body] }
15
+ super
16
+ end
17
+
18
+ def on_complete(env)
19
+ debug "RESPONSE: #{env[:status]} #{env[:method].upcase} #{env[:url].to_s}"
20
+ debug('response') { dump_headers env[:response_headers] }
21
+ debug('response.body') { env[:body] }
22
+ debug('')
23
+ end
24
+
25
+ private
26
+
27
+ def dump_headers(headers)
28
+ (headers || {}).map { |k,v| "#{k}: #{v.inspect}" }.join("\n")
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ class Assemble::Client::Tag < Cistern::Model
2
+
3
+ identity :id, aliases: ["ObjectID", "_refObjectUUID"]
4
+
5
+ attribute :archived, aliases: "Archived", type: :boolean, default: false
6
+ attribute :name, aliases: ["Name", "_objectName"]
7
+ attribute :version, aliases: ["VersionId", "_objectVersion"]
8
+ attribute :created_at, aliases: ["_CreatedDate", "CreationDate"], type: :time
9
+
10
+ def save
11
+ response = if new_record?
12
+ self.connection.create_tag(archived: self.archived, name: self.name)
13
+ else
14
+ self.connection.update_tag(self.identity, archived: self.archived, name: self.name)
15
+ end
16
+ merge_attributes(response.body["CreateResult"]["Object"])
17
+ end
18
+
19
+ def archive!
20
+ self.archived = true
21
+ self.connection.update_tag(self.identity, archived: self.archived)
22
+ end
23
+
24
+ alias destroy archive!
25
+ end
@@ -0,0 +1,13 @@
1
+ class Assemble::Client::Tags < Cistern::Collection
2
+
3
+ model Assemble::Client::Tag
4
+
5
+ def all(options={})
6
+ results = self.connection.get_tags.body["QueryResult"]["Results"]
7
+ self.load(results.map { |r| {"id" => r["_refObjectUUID"], "name" => r["_refObjectName"]} })
8
+ end
9
+
10
+ def get(object_id)
11
+ self.new(self.connection.get_tag(object_id).body["Tag"])
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ class Assemble::Client
2
+ class Real
3
+ def create_tag(attributes)
4
+ request(
5
+ :body => {"Tag" => attributes},
6
+ :path => "/tag/create",
7
+ :method => :post,
8
+ )
9
+ end
10
+ end # Real
11
+ end
@@ -0,0 +1,11 @@
1
+ class Assemble::Client
2
+ class Real
3
+ def destroy_tag(id)
4
+ request(
5
+ :body => {"Tag" => attributes},
6
+ :path => "/tag/create",
7
+ :method => :post,
8
+ )
9
+ end
10
+ end # Real
11
+ end
@@ -0,0 +1,10 @@
1
+ class Assemble::Client
2
+ class Real
3
+ def get_tag(id)
4
+ request(
5
+ :body => nil,
6
+ :path => "/tags/#{id}",
7
+ )
8
+ end
9
+ end # Real
10
+ end
@@ -0,0 +1,9 @@
1
+ class Assemble::Client
2
+ class Real
3
+ def get_tags(params={})
4
+ request(
5
+ :path => "/tags",
6
+ )
7
+ end
8
+ end # Real
9
+ end
@@ -0,0 +1,11 @@
1
+ class Assemble::Client
2
+ class Real
3
+ def update_tag(id, attributes)
4
+ request(
5
+ :body => {"Tag" => attributes},
6
+ :path => "/tag/#{id}",
7
+ :method => :post,
8
+ )
9
+ end
10
+ end # Real
11
+ end
@@ -0,0 +1,63 @@
1
+ class Assemble::Response
2
+ class Error < StandardError
3
+ attr_reader :response
4
+
5
+ def initialize(response)
6
+ @response = response
7
+ super(
8
+ {
9
+ :body => response.body,
10
+ :headers => response.headers,
11
+ :request => response.request,
12
+ :status => response.status,
13
+ }.inspect
14
+ )
15
+ end
16
+
17
+ def errors
18
+ response.body["errors"]
19
+ end
20
+
21
+ def full_messages
22
+ if errors.is_a?(Hash)
23
+ errors.inject([]){|r,(k,v)| r += v.map{|s| "#{k.capitalize} #{s}"}}
24
+ else # Array or String
25
+ errors
26
+ end
27
+ end
28
+ end
29
+
30
+ BadRequest = Class.new(Error)
31
+ NotFound = Class.new(Error)
32
+ Unprocessable = Class.new(Error)
33
+ Conflict = Class.new(Error)
34
+ Unexpected = Class.new(Error)
35
+
36
+ EXCEPTION_MAPPING = {
37
+ 400 => BadRequest,
38
+ 404 => NotFound,
39
+ 409 => Conflict,
40
+ 422 => Unprocessable,
41
+ 500 => Unexpected,
42
+ }
43
+
44
+ attr_reader :headers, :status, :body, :request
45
+
46
+ def initialize(options={})
47
+ @status = options[:status]
48
+ @headers = options[:headers]
49
+ @body = options[:body]
50
+ @request = options[:request]
51
+ end
52
+
53
+ def successful?
54
+ self.status >= 200 && self.status <= 299 || self.status == 304
55
+ end
56
+
57
+ def raise!
58
+ if !successful?
59
+ raise((EXCEPTION_MAPPING[self.status] || Error).new(self))
60
+ else self
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module Assemble
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ ENV['MOCK_ASSEMBLE'] ||= 'true'
2
+ ENV['RALLY_URL'] ||= "https://rally1.rallydev.com/slm/webservice/"
3
+
4
+ Bundler.require(:test, :default)
5
+
6
+ require File.expand_path("../../lib/assemble", __FILE__)
7
+
8
+ Dir[File.expand_path("../{shared,support}/*.rb", __FILE__)].each { |f| require(f) }
9
+
10
+ Cistern.formatter = Cistern::Formatter::AwesomePrint
11
+
12
+ if ENV['MOCK_ASSEMBLE'] == 'true'
13
+ Assemble::Client.mock!
14
+ end
15
+
16
+ Assemble::Client::Mock.timeout = 0
17
+ Assemble::Client::Mock.poll_interval = 0
18
+ Assemble::Client::Real.timeout = 10
19
+
20
+ RSpec.configure do |config|
21
+ config.filter_run_excluding(mock_only: true) unless ENV['MOCK_ASSEMBLE'] == "true"
22
+ config.order = :random
23
+
24
+ config.before(:each) do
25
+ Assemble::Client.reset! if Assemble::Client.mocking?
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module ClientHelper
2
+ def create_client(options={})
3
+ client_options = {}
4
+ client_options.merge!(token: options[:token] || File.read(File.expand_path("../../../.assemble", __FILE__)).strip)
5
+ client_options.merge!(logger: Logger.new(STDOUT)) if ENV["VERBOSE"]
6
+
7
+ Assemble::Client.new(client_options)
8
+ end
9
+ end
10
+
11
+ RSpec.configure { |config| config.include(ClientHelper) }
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'tags' do
4
+ let!(:client) { create_client }
5
+ let!(:tag) { client.tags.create(name: "assemble") }
6
+
7
+ after(:each) { tag.destroy}
8
+
9
+ it "should get tags" do
10
+ expect(client.tags.all.map(&:id)).to include(tag.identity)
11
+ end
12
+
13
+ it "should get a tag" do
14
+ fetched = client.tags.get(tag.identity)
15
+
16
+ expect(tag.name).to eq("assemble")
17
+ expect(fetched).to eq(tag)
18
+ expect(fetched.name).to eq("assemble")
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: assemble
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Josh Lane
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-17 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cistern
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday_middleware
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: addressable
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Cistern-based client for Rally Dev
98
+ email:
99
+ - me@joshualane.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - Guardfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - assemble.gemspec
111
+ - lib/assemble.rb
112
+ - lib/assemble/client.rb
113
+ - lib/assemble/logger.rb
114
+ - lib/assemble/models/tag.rb
115
+ - lib/assemble/models/tags.rb
116
+ - lib/assemble/requests/create_tag.rb
117
+ - lib/assemble/requests/destroy_tag.rb
118
+ - lib/assemble/requests/get_tag.rb
119
+ - lib/assemble/requests/get_tags.rb
120
+ - lib/assemble/requests/update_tag.rb
121
+ - lib/assemble/response.rb
122
+ - lib/assemble/version.rb
123
+ - spec/spec_helper.rb
124
+ - spec/support/client_helper.rb
125
+ - spec/tags_spec.rb
126
+ homepage: ''
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.2.2
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Rally REST API Client
150
+ test_files:
151
+ - spec/spec_helper.rb
152
+ - spec/support/client_helper.rb
153
+ - spec/tags_spec.rb
154
+ has_rdoc: