camper 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,83 @@
1
+ module Camper
2
+ class Resource
3
+
4
+ Dir[File.expand_path('resources/*.rb', __dir__)].each { |f| require f }
5
+
6
+ # Creates a new Resource object.
7
+ def initialize(hash)
8
+ @hash = hash
9
+ @data = resourcify_data
10
+ end
11
+
12
+ # @return [Hash] The original hash.
13
+ def to_hash
14
+ hash
15
+ end
16
+ alias to_h to_hash
17
+
18
+ # @return [String] Formatted string with the class name, object id and original hash.
19
+ def inspect
20
+ "#<#{self.class}:#{object_id} {hash: #{hash.inspect}}"
21
+ end
22
+
23
+ def [](key)
24
+ data[key]
25
+ end
26
+
27
+ # Check whether a resource can be commented on or not
28
+ # given the presences of `comments_count` and `comments_url` keys
29
+ #
30
+ # @return [Boolean]
31
+ def can_be_commented?
32
+ hash.key?('comments_url') && hash.key?('comments_count')
33
+ end
34
+
35
+ def self.create(hash)
36
+ klass = detect_type(hash["url"])
37
+
38
+ return klass.new(hash)
39
+ end
40
+
41
+ private
42
+
43
+ attr_reader :hash, :data
44
+
45
+ def resourcify_data
46
+ @hash.each_with_object({}) do |(key, value), data|
47
+ value = resourcify_value(value)
48
+
49
+ data[key.to_s] = value
50
+ end
51
+ end
52
+
53
+ def resourcify_value(input)
54
+ return Resource.new(input) if input.is_a? Hash
55
+
56
+ return input unless input.is_a? Array
57
+
58
+ input.map { |curr| resourcify_value(curr) }
59
+ end
60
+
61
+ # Respond to messages for which `self.data` has a key
62
+ def method_missing(method_name, *args, &block)
63
+ @data.key?(method_name.to_s) ? @data[method_name.to_s] : super
64
+ end
65
+
66
+ # rubocop:disable Style/OptionalBooleanParameter
67
+ def respond_to_missing?(method_name, include_private = false)
68
+ @hash.keys.map(&:to_sym).include?(method_name.to_sym) || super
69
+ end
70
+ # rubocop:enable Style/OptionalBooleanParameter
71
+
72
+ def self.detect_type(url)
73
+ case url
74
+ when /#{Configuration.base_api_endpoint}\/\d+\/projects\/\d+\.json/
75
+ return Project
76
+ else
77
+ return Resource
78
+ end
79
+ end
80
+
81
+ private_class_method :detect_type
82
+ end
83
+ end
@@ -0,0 +1,14 @@
1
+ module Camper
2
+ class Project < Resource
3
+
4
+ attr_reader :message_board, :todoset, :schedule
5
+
6
+ def initialize(hash)
7
+ super
8
+
9
+ @message_board = dock.find { |payload| payload.name == 'message_board' }
10
+ @todoset = dock.find { |payload| payload.name == 'todoset' }
11
+ @schedule = dock.find { |payload| payload.name == 'schedule' }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Camper
4
+ VERSION = '0.0.5'
5
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: camper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - renehernandez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-09-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.18'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.18'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.9'
69
+ description:
70
+ email:
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".editorconfig"
76
+ - ".github/dependabot.yml"
77
+ - ".github/workflows/ci.yml"
78
+ - ".github/workflows/ci_changelog.yml"
79
+ - ".github/workflows/release.yml"
80
+ - ".gitignore"
81
+ - ".rspec"
82
+ - ".rubocop.yml"
83
+ - ".rubocop_todo.yml"
84
+ - ".ruby-version"
85
+ - CHANGELOG.md
86
+ - CONTRIBUTING.md
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - LICENSE
90
+ - README.md
91
+ - Rakefile
92
+ - bin/console
93
+ - bin/setup
94
+ - camper.gemspec
95
+ - examples/comments.rb
96
+ - examples/messages.rb
97
+ - examples/oauth.rb
98
+ - examples/obtain_acces_token.rb
99
+ - examples/todos.rb
100
+ - lib/camper.rb
101
+ - lib/camper/api/comment.rb
102
+ - lib/camper/api/message.rb
103
+ - lib/camper/api/project.rb
104
+ - lib/camper/api/resource.rb
105
+ - lib/camper/api/todo.rb
106
+ - lib/camper/authorization.rb
107
+ - lib/camper/client.rb
108
+ - lib/camper/configuration.rb
109
+ - lib/camper/error.rb
110
+ - lib/camper/logging.rb
111
+ - lib/camper/paginated_response.rb
112
+ - lib/camper/pagination_data.rb
113
+ - lib/camper/request.rb
114
+ - lib/camper/resource.rb
115
+ - lib/camper/resources/project.rb
116
+ - lib/camper/version.rb
117
+ homepage: https://github.com/renehernandez/camper
118
+ licenses:
119
+ - MIT
120
+ metadata:
121
+ allowed_push_host: https://rubygems.org
122
+ homepage_uri: https://github.com/renehernandez/camper
123
+ source_code_uri: https://github.com/renehernandez/camper
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 2.5.0
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubygems_version: 3.1.2
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Ruby client for Basecamp 3 API
143
+ test_files: []