restpack_activity 0.0.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: db7b4d6d9f6d840e9d6c287011efac6b42be02b0
4
+ data.tar.gz: b5c61aa7bd9e189947a120044c0c26bf73fb4050
5
+ SHA512:
6
+ metadata.gz: dd50d4949d04b1fc3071211ab681a29902dd3669594e849e3b4906f35546e9bfa1eb69fb31171ea52172bbb530d370bc0f9277de6b89906f1f0ba230941a2a34
7
+ data.tar.gz: 917e482c25ef8159f85a0a7a2797dd8408f873cb3cca38dc0e746439f362602edccecf579225b496ac530103e560ca4ffdcee4e09e58ba8a32cb46296a89093c
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in restpack_activity.gemspec
4
+ gemspec
5
+
6
+ #TODO: GJ: move to gemspec when restpack_activity_service has been released
7
+ gem 'restpack_activity_service', path: '../restpack_activity_service'
8
+ gem 'restpack_service', path: '../restpack_service'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Gavin Joyce
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # RestpackActivity
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'restpack_activity'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install restpack_activity
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
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 new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "restpack_gem"
2
+ RestPack::Gem::Tasks.load_tasks
@@ -0,0 +1,10 @@
1
+ module RestPack::Activity
2
+ class Configuration
3
+ attr_accessor :service_type, :application_id, :api_domain, :api_token
4
+
5
+ def initialize
6
+ @service_type = :local
7
+ @application_id = 1
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,116 @@
1
+ class Activity
2
+ include ActiveModel::Model
3
+
4
+ attr_accessor :id, :application_id, :user_id, :title, :content, :tags,
5
+ :latitude, :longitude, :access, :data, :href, :created_at, :updated_at
6
+ validates_presence_of :user_id, :content
7
+
8
+ def initialize(params={})
9
+ @tags = []
10
+ @access = []
11
+ super(params)
12
+ end
13
+
14
+ def self.get(id)
15
+ response = service.get(id)
16
+ Activity.new(response.result)
17
+ end
18
+
19
+ def self.destroy(id)
20
+ service.destroy(id)
21
+ true
22
+ end
23
+
24
+ def self.list(params = {})
25
+ response = service.list(params)
26
+
27
+ Page.new(response, :activities) do |activity|
28
+ Activity.new(activity)
29
+ end
30
+ end
31
+
32
+ def tags_csv=(csv)
33
+ @tags = csv.split(',')
34
+ end
35
+
36
+ def tags_csv
37
+ @tags.join(',')
38
+ end
39
+
40
+ def access_csv=(csv)
41
+ @access = csv.split(',')
42
+ end
43
+
44
+ def access_csv
45
+ @access.join(',')
46
+ end
47
+
48
+ def save
49
+ if valid?
50
+ response = new? ? service.create(attributes) : service.update(attributes)
51
+
52
+ if response.success?
53
+ #TODO: GJ: update model attributes?
54
+ return true
55
+ else
56
+ response.errors.each do |key, messages|
57
+ messages.each do |message|
58
+ errors.add(key, message)
59
+ end
60
+ end
61
+
62
+ return false
63
+ end
64
+ end
65
+
66
+ nil
67
+ end
68
+
69
+ def new?
70
+ @id.nil?
71
+ end
72
+
73
+ def persisted?
74
+ !new?
75
+ end
76
+
77
+ def update_attributes(params)
78
+ #TODO: whitelist updateble params
79
+ @title = params[:title] if params[:title]
80
+ @content = params[:content] if params[:content]
81
+ @latitude = params[:latitude] if params[:latitude]
82
+ @longitude = params[:longitude] if params[:longitude]
83
+ @data = params[:data] if params[:data]
84
+ self.tags_csv = params[:tags_csv] if params[:tags_csv]
85
+ self.access_csv = params[:access_csv] if params[:access_csv]
86
+ end
87
+
88
+ def self.service
89
+ klass = "RestPack::Activity::Proxies::#{RestPack::Activity.config.service_type.capitalize}"
90
+ klass.classify.constantize
91
+ end
92
+
93
+ def service
94
+ self.class.service
95
+ end
96
+
97
+ private
98
+
99
+ def attributes
100
+ #TODO: GJ: only those that have changed
101
+ hash = {
102
+ id: @id,
103
+ application_id: @application_id,
104
+ user_id: @user_id,
105
+ title: @title,
106
+ content: @content,
107
+ data: @data,
108
+ tags: @tags.join(','),
109
+ access: @access.join(',')
110
+ }
111
+
112
+ hash[:latitude] = @latitude unless @latitude.blank?
113
+ hash[:longitude] = @longitude unless @longitude.blank?
114
+ hash
115
+ end
116
+ end
@@ -0,0 +1,58 @@
1
+ require 'forwardable'
2
+
3
+ class Page
4
+ include Enumerable
5
+ extend Forwardable
6
+
7
+ def_delegators :@items, :each, :<<
8
+
9
+ attr_reader :response, :items
10
+
11
+ def initialize(response, key)
12
+ @response = response
13
+ @key = key
14
+ @items = []
15
+
16
+ response.result[key].each do |item|
17
+ @items << yield(item)
18
+ end
19
+ end
20
+
21
+ def count
22
+ meta :count
23
+ end
24
+
25
+ def page
26
+ meta :page
27
+ end
28
+
29
+ def page_size
30
+ meta :page_size
31
+ end
32
+
33
+ def page_count
34
+ meta :page_count
35
+ end
36
+
37
+ def previous_page
38
+ meta :previous_page
39
+ end
40
+
41
+ def next_page
42
+ meta :next_page
43
+ end
44
+
45
+ def previous_page?
46
+ previous_page != nil
47
+ end
48
+
49
+ def next_page?
50
+ next_page != nil
51
+ end
52
+
53
+ private
54
+
55
+ def meta(property)
56
+ @response.result[:meta][@key][property]
57
+ end
58
+ end
@@ -0,0 +1,37 @@
1
+ require 'rest_client'
2
+
3
+ module RestPack::Activity::Proxies
4
+ class Api < RestPack::BaseProxy
5
+ def self.get(id)
6
+ http(:get, "/api/v1/activities/#{id}.json")
7
+ end
8
+
9
+ def self.list(params = {})
10
+ http(:get, "/api/v1/activities.json", params)
11
+ end
12
+
13
+ def self.create(params)
14
+ http(:post, "/api/v1/activities.json", params)
15
+ end
16
+
17
+ def self.update(params)
18
+ http(:put, "/api/v1/activities/#{params[:id]}.json", params)
19
+ end
20
+
21
+ def self.destroy(id)
22
+ http(:delete, "/api/v1/activities/#{id}.json")
23
+ end
24
+
25
+ private
26
+
27
+ def self.http(method, path, params = {})
28
+ params = { params: params } if method == :get
29
+
30
+ RestClient.send(method, "#{RestPack::Activity.config.api_domain}#{path}", params) do |rest_response|
31
+ response = RestPack::Response.from_rest(rest_response)
32
+ raise_exceptions_if_required(response)
33
+ response
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,50 @@
1
+ module RestPack::Activity::Proxies
2
+ class Local < RestPack::BaseProxy
3
+ def self.get(id)
4
+ response = RestPack::Services::Activity::Get.run({
5
+ id: id,
6
+ application_id: RestPack::Activity.config.application_id
7
+ })
8
+
9
+ raise_exceptions_if_required(response)
10
+ response
11
+ end
12
+
13
+ def self.list(params = {})
14
+ response = RestPack::Services::Activity::List.run(params, {
15
+ application_id: RestPack::Activity.config.application_id
16
+ })
17
+
18
+ raise_exceptions_if_required(response)
19
+ response
20
+ end
21
+
22
+ def self.create(params)
23
+ response = RestPack::Services::Activity::Create.run(params, {
24
+ application_id: RestPack::Activity.config.application_id
25
+ })
26
+
27
+ raise_exceptions_if_required(response)
28
+ response
29
+ end
30
+
31
+ def self.update(params)
32
+ response = RestPack::Services::Activity::Update.run(params, {
33
+ application_id: RestPack::Activity.config.application_id
34
+ })
35
+
36
+ raise_exceptions_if_required(response)
37
+ response
38
+ end
39
+
40
+ def self.destroy(id)
41
+ response = RestPack::Services::Activity::Destry.run({
42
+ id: id,
43
+ application_id: RestPack::Activity.config.application_id
44
+ })
45
+
46
+ raise_exceptions_if_required(response)
47
+ response
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,14 @@
1
+ require 'rest_client'
2
+
3
+ module RestPack
4
+ class BaseProxy
5
+ def self.raise_exceptions_if_required(response)
6
+ if !response.success?
7
+ case(response.status)
8
+ when :not_found
9
+ raise ActiveRecord::RecordNotFound
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module RestPack
2
+ module Activity
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ require "active_model"
2
+ require "active_support/core_ext"
3
+
4
+ require "restpack_activity/version"
5
+ require "restpack_activity/configuration"
6
+ require "restpack_activity/models/page"
7
+ require "restpack_activity/models/activity"
8
+
9
+ require "restpack_activity/proxies/base_proxy"
10
+ require "restpack_activity/proxies/activity/api"
11
+ require "restpack_activity/proxies/activity/local"
12
+
13
+
14
+ module RestPack
15
+ module Activity
16
+ mattr_accessor :config
17
+ @@config = Configuration.new
18
+
19
+ def self.setup
20
+ yield @@config
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'restpack_activity/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "restpack_activity"
8
+ spec.version = RestPack::Activity::VERSION
9
+ spec.authors = ["Gavin Joyce"]
10
+ spec.email = ["gavinjoyce@gmail.com"]
11
+ spec.description = %q{A client gem to the activity service}
12
+ spec.summary = %q{A client gem to the activity service}
13
+ spec.homepage = "https://github.com/RestPack"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_dependency "restpack_gem", "~> 0.0.9"
22
+ spec.add_dependency "activemodel", "~> 4.0.0"
23
+ spec.add_dependency "activesupport", "~> 4.0"
24
+ spec.add_dependency "rest-client", "~> 1.6.7"
25
+ spec.add_dependency "yajl-ruby", "~> 1.1.0"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.3"
28
+ spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "rspec"
30
+ spec.add_development_dependency "bump"
31
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe RestPack::Activity::Configuration do
4
+ context "defaults" do
5
+ it "has default service_type" do
6
+ RestPack::Activity.config.service_type.should == :local
7
+ end
8
+
9
+ it "has default application_id" do
10
+ RestPack::Activity.config.application_id.should == 1
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Activity do
4
+ describe ".service proxy" do
5
+ before { @original = RestPack::Activity.config.service_type }
6
+ after { RestPack::Activity.config.service_type = @original }
7
+
8
+ it "resolves :local proxy" do
9
+ RestPack::Activity.config.service_type = :local
10
+ Activity.service.should == RestPack::Activity::Proxies::Local
11
+ end
12
+
13
+ it "resolves :api proxy" do
14
+ RestPack::Activity.config.service_type = :api
15
+ Activity.service.should == RestPack::Activity::Proxies::Api
16
+ end
17
+ end
18
+ end
@@ -0,0 +1 @@
1
+ require 'restpack_activity'
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: restpack_activity
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Gavin Joyce
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: restpack_gem
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.9
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.9
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.7
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.6.7
69
+ - !ruby/object:Gem::Dependency
70
+ name: yajl-ruby
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.1.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: bump
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: A client gem to the activity service
140
+ email:
141
+ - gavinjoyce@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - .gitignore
147
+ - .rspec
148
+ - Gemfile
149
+ - LICENSE.txt
150
+ - README.md
151
+ - Rakefile
152
+ - lib/restpack_activity.rb
153
+ - lib/restpack_activity/configuration.rb
154
+ - lib/restpack_activity/models/activity.rb
155
+ - lib/restpack_activity/models/page.rb
156
+ - lib/restpack_activity/proxies/activity/api.rb
157
+ - lib/restpack_activity/proxies/activity/local.rb
158
+ - lib/restpack_activity/proxies/base_proxy.rb
159
+ - lib/restpack_activity/version.rb
160
+ - restpack_activity.gemspec
161
+ - spec/configuration_spec.rb
162
+ - spec/models/activity_spec.rb
163
+ - spec/spec_helper.rb
164
+ homepage: https://github.com/RestPack
165
+ licenses:
166
+ - MIT
167
+ metadata: {}
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubyforge_project:
184
+ rubygems_version: 2.0.3
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: A client gem to the activity service
188
+ test_files:
189
+ - spec/configuration_spec.rb
190
+ - spec/models/activity_spec.rb
191
+ - spec/spec_helper.rb