easy-resources 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8fd07ee79595de5aa8d8593b72e41c8d9add75d318de5aca79492f3a6d1fde37
4
+ data.tar.gz: 69065267e4aa1f5fea0c53eec9c5a57b2b881fa0a1dd2c036922146d0927ae46
5
+ SHA512:
6
+ metadata.gz: 1cbbe3cf6197b02b8e5ce78510fbd08a277b70cfc2969d27523f96ec2a7c36ec425a1dcc822d80d58a0989d165ce277f5920ad673cf8c0c5dc462e46d8d18f64
7
+ data.tar.gz: e0ae5e3e2b036aac7ef75111102d9bb0676ed8d9b0168f2b3ebf6587244055a9b4f67ada282fb7153a1c87b6ce793d203ef0b37d0a1803ffbff553ef504aca7c
@@ -0,0 +1,20 @@
1
+ Copyright 2018 petr
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # EasyResources
2
+
3
+ [![pipeline status](https://git.easy.cz/easy/resources/badges/master/pipeline.svg)](https://git.easy.cz/easy/resources/commits/master)
4
+ [![coverage report](https://git.easy.cz/easy/resources/badges/master/coverage.svg)](http://easy.pages.easycloud.cz/resources)
5
+
6
+ Common implementation of Active Resource for our projects / microservices.
7
+
8
+ Allow communicate via API with (Easy)Redmine applications.
9
+
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'easy_resources'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ ## Development
24
+
25
+ run bundle install install and do not forget to run `rspec`.
26
+
27
+ ## Contributing
28
+
29
+ For contributing please strictly follow our [guideline](https://git.easy.cz/external/guidelines/blob/master/DEV/CODE_STYLE.md). MR are welcome. As a target branch use always `devel`
30
+
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
35
+
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Easy::Resource'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,43 @@
1
+ module Easy
2
+ class Resource < ActiveResource::Base
3
+
4
+ def self.configure(conf)
5
+ self.api_key = conf[:api_key]
6
+ self.site = conf[:url]
7
+ end
8
+
9
+ def becomes(entity_class)
10
+ model = entity_class.new
11
+ model.attributes = self.attributes
12
+ model
13
+ end
14
+
15
+ def patch(method_name, options = {}, body = "")
16
+ if method_name.nil?
17
+ connection.patch(element_path(options), body, self.class.headers)
18
+ else
19
+ super
20
+ end
21
+ end
22
+
23
+ def update_column(attribute, value)
24
+ update_columns(attribute.to_sym => value)
25
+ end
26
+
27
+ def update_columns(**attributes)
28
+ patch(nil, {}, encode_attributes(attributes))
29
+ end
30
+
31
+ protected
32
+
33
+ def encode_attributes(**attributes)
34
+ case self.class.format.extension
35
+ when "json"
36
+ attributes.to_json(include_root_in_json ? { root: self.class.element_name } : {})
37
+ when "xml"
38
+ attributes.to_xml(root: self.class.element_name)
39
+ end
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,26 @@
1
+ require "activeresource"
2
+ require "activeresource-response"
3
+
4
+ require "easy/resources/railtie"
5
+
6
+ module Easy
7
+ autoload :Resource, "easy/resource"
8
+
9
+ module Resources
10
+
11
+ module Redmine
12
+ extend ActiveSupport::Autoload
13
+
14
+ autoload :RedmineBase
15
+ autoload :EasyContact
16
+ autoload :EasyCrmCase
17
+ autoload :EasyServer
18
+ autoload :EasyWebApplication
19
+ autoload :EasyWebApplicationActivity
20
+ autoload :Issue
21
+ autoload :Project
22
+
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module Easy
2
+ module Resources
3
+ class Railtie < ::Rails::Railtie
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module Easy
2
+ module Resources
3
+ module Redmine
4
+ class EasyContact < RedmineBase
5
+
6
+ self.element_name = 'easy_contact'
7
+
8
+ def name
9
+ "#{firstname} #{lastname}"
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ module Easy
2
+ module Resources
3
+ module Redmine
4
+ class EasyCrmCase < RedmineBase
5
+
6
+ self.element_name = 'easy_crm_case'
7
+
8
+ belongs_to :project, class_name: 'Easy::Resources::Redmine::Project'
9
+ belongs_to :main_easy_contact, class_name: 'Easy::Resources::Redmine::EasyContact'
10
+
11
+ # Alias for main_contact
12
+ # @return [Easy::Resources::Redmine::EasyContact]
13
+ def customer
14
+ main_easy_contact
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ module Easy
2
+ module Resources
3
+ module Redmine
4
+ class EasyServer < RedmineBase
5
+
6
+ self.element_name = 'easy_server'
7
+
8
+ has_many :easy_web_applications, class_name: 'Easy::Resources::Redmine::EasyWebApplication'
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ module Easy
2
+ module Resources
3
+ module Redmine
4
+ class EasyWebApplication < RedmineBase
5
+
6
+ self.element_name = 'easy_web_application'
7
+
8
+ self.schema = {
9
+ url: :string,
10
+ git_repository: :string,
11
+ git_branch: :string,
12
+ easy_crm_case_id: :integer,
13
+ easy_contact_id: :integer
14
+ }
15
+
16
+ belongs_to :easy_server, class_name: 'Easy::Resources::Redmine::EasyServer'
17
+ belongs_to :easy_contact, class_name: 'Easy::Resources::Redmine::EasyContact'
18
+ belongs_to :easy_crm_case, class_name: 'Easy::Resources::Redmine::EasyCrmCase'
19
+
20
+ has_many :easy_web_application_activities, class_name: 'Easy::Resources::Redmine::EasyWebApplicationActivity'
21
+ has_one :easy_web_application_activity, class_name: 'Easy::Resources::Redmine::EasyWebApplicationActivity'
22
+
23
+ def name
24
+ url
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ module Easy
2
+ module Resources
3
+ module Redmine
4
+ class EasyWebApplicationActivity < RedmineBase
5
+
6
+ self.element_name = 'easy_web_application_activity'
7
+
8
+ belongs_to :easy_web_application, class_name: 'Easy::Resources::Redmine::EasyWebApplication'
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Easy
2
+ module Resources
3
+ module Redmine
4
+ class Issue < RedmineBase
5
+
6
+ self.element_name = 'issue'
7
+
8
+ belongs_to :project, class_name: 'Easy::Resources::Redmine::Project'
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Easy
2
+ module Resources
3
+ module Redmine
4
+ class Project < RedmineBase
5
+
6
+ self.element_name = 'project'
7
+
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,50 @@
1
+ module Easy
2
+ module Resources
3
+ module Redmine
4
+ class RedmineBase < ::Easy::Resource
5
+
6
+ self.include_root_in_json = true
7
+ self.format = :xml
8
+ self.add_response_method :http_response
9
+
10
+ class << self
11
+
12
+ def api_key=(key)
13
+ @api_key = key
14
+ end
15
+
16
+ def configure(conf = nil)
17
+ conf ||= Easy.config.sites.redmine
18
+ super(conf)
19
+ end
20
+
21
+ def headers
22
+ h = super
23
+ h['X-Redmine-API-Key'] ||= @api_key
24
+ h
25
+ end
26
+
27
+ def get_all(**params, &block)
28
+ records = results = all(params: params)
29
+ response = results.http_response
30
+ total = response['Total'].to_i
31
+ current_page = 1
32
+
33
+ while records.any?
34
+ records.each(&block) if block_given?
35
+ break if results.size >= total
36
+
37
+ self.format = :xml
38
+
39
+ records = all(params: params.merge(page: (current_page += 1)))
40
+ results.concat(records)
41
+ end
42
+
43
+ results
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,2 @@
1
+ x= File.expand_path('../../../../', __FILE__)
2
+ Dir["#{x}/spec/support/**/*.rb"].sort.each { |f| require f }
@@ -0,0 +1,5 @@
1
+ module Easy
2
+ module Resources
3
+ VERSION = '0.5.3'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy-resources
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.3
5
+ platform: ruby
6
+ authors:
7
+ - petr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activeresource
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activeresource-response
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: easy-configuration
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.3.6
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.3.6
125
+ description: Description of Easy::Resources.
126
+ email:
127
+ - petr@easy.cz
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - MIT-LICENSE
133
+ - README.md
134
+ - Rakefile
135
+ - lib/easy/resource.rb
136
+ - lib/easy/resources.rb
137
+ - lib/easy/resources/railtie.rb
138
+ - lib/easy/resources/redmine/easy_contact.rb
139
+ - lib/easy/resources/redmine/easy_crm_case.rb
140
+ - lib/easy/resources/redmine/easy_server.rb
141
+ - lib/easy/resources/redmine/easy_web_application.rb
142
+ - lib/easy/resources/redmine/easy_web_application_activity.rb
143
+ - lib/easy/resources/redmine/issue.rb
144
+ - lib/easy/resources/redmine/project.rb
145
+ - lib/easy/resources/redmine/redmine_base.rb
146
+ - lib/easy/resources/spec_helper.rb
147
+ - lib/easy/resources/version.rb
148
+ homepage: https://www.easysoftware.com
149
+ licenses:
150
+ - MIT
151
+ metadata:
152
+ allowed_push_host: https://rubygems.org
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.7.7
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Summary of Easy::Resources.
173
+ test_files: []