apphoshies-ruby-client 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -21,3 +21,7 @@
21
21
  === 0.4.0
22
22
 
23
23
  * File Upload Support
24
+
25
+ === 0.5.0
26
+
27
+ * Refactoring, Addition of all basic system objects
data/Manifest.txt CHANGED
@@ -4,10 +4,14 @@ PostInstall.txt
4
4
  README.rdoc
5
5
  Rakefile
6
6
  lib/apphoshies_client.rb
7
- lib/apphoshies_client/class_methods.rb
8
7
  lib/apphoshies_client/configuration.rb
8
+ lib/apphoshies_client/exceptions.rb
9
+ lib/apphoshies_client/base.rb
9
10
  lib/apphoshies_client/device_token.rb
10
11
  lib/apphoshies_client/document.rb
12
+ lib/apphoshies_client/content_item.rb
13
+ lib/apphoshies_client/tracking_item.rb
14
+ lib/apphoshies_client/user.rb
11
15
  lib/apphoshies_client/message.rb
12
16
  lib/apphoshies_client/file_upload.rb
13
17
  script/console
data/README.rdoc CHANGED
@@ -4,15 +4,37 @@
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- The App Hoshies infrastructure is based on REST Webservices. For your convenience client frameworks are provided to interact with your data.
7
+ The App Hoshies App Data Cloud is based on REST Webservices. For your convenience client frameworks are provided to interact with your data (iOS/Android/Ruby). At the moment the App Data Cloud is in private beta mode. Please contact support (at) apphoshies (dot) com if you want to try it out.
8
+
9
+ Please visit http://apphoshies.com/service for more information.
8
10
 
9
11
  == FEATURES/PROBLEMS:
10
12
 
11
- * Documents, Device Tokens, Documents
13
+ * Documents, Device Tokens, Documents, Messages
12
14
 
13
15
  == SYNOPSIS:
16
+ Create an apphoshies.yml in the current directory or an .apphoshies.yml file in your home directory
17
+
18
+ @@apphoshies_configuration = ApphoshiesClient::Configuration.new
19
+ @@apphoshies_configuration.config
20
+
21
+ document = ApphoshiesClient::Document.find_one(params[:some_id])
22
+ documents = ApphoshiesClient::Document.all(:datasource => 'test', :limit => 10)
23
+
24
+ Creating a push message for a single device
25
+
26
+ message = ApphoshiesClient::Message.new(:app_id => 'Your App Name', :application_client_key => 'the target device key', :message => 'Your Message')
27
+ message.save
28
+
29
+ Sending a push message to all devices of an app
14
30
 
15
- FIX (code sample of usage)
31
+ message = ApphoshiesClient::Message.new(:app_id => 'Your App Name', :application_client_key => 'all', :message => 'Your Message')
32
+ message.save
33
+
34
+ Retrieving a file uploads of a user (identified by the application_client_key of the app installation)
35
+
36
+ file_uploads = ApphoshiesClient::FileUpload.find_by_application_client_key('the target device key', {:document_id => 'document id association'})
37
+ puts file_uploads.first.url
16
38
 
17
39
  == REQUIREMENTS:
18
40
 
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module ApphoshiesClient
5
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
 
8
8
  require "rubygems"
@@ -11,7 +11,7 @@ require 'active_resource'
11
11
 
12
12
  ActiveResource::Base.include_root_in_json = true
13
13
 
14
- require 'apphoshies_client/class_methods'
14
+ require 'apphoshies_client/exceptions'
15
15
  require 'apphoshies_client/configuration'
16
16
  @@apphoshies_configuration = ApphoshiesClient::Configuration.new
17
17
  @@apphoshies_configuration.site = 'https://service.apphoshies.com'
@@ -19,7 +19,17 @@ require 'apphoshies_client/configuration'
19
19
  @@apphoshies_configuration.api_key = ''
20
20
  @@apphoshies_configuration.app_id = ''
21
21
 
22
+ require 'apphoshies_client/base'
22
23
  require 'apphoshies_client/device_token'
23
24
  require 'apphoshies_client/document'
25
+ require 'apphoshies_client/content_item'
26
+ require 'apphoshies_client/user'
27
+ require 'apphoshies_client/tracking_item'
24
28
  require 'apphoshies_client/message'
25
29
  require 'apphoshies_client/file_upload'
30
+
31
+ #def load_development_configuration
32
+ # @@apphoshies_configuration = ApphoshiesClient::Configuration.new
33
+ # @@apphoshies_configuration.config
34
+ # @@apphoshies_configuration.site = 'http://192.168.0.104:3000'
35
+ #end
@@ -0,0 +1,33 @@
1
+ class ApphoshiesClient::Base < ActiveResource::Base
2
+ def self.get(query_symbol, options = {})
3
+ reload_http_headers
4
+
5
+ if @@apphoshies_configuration.app_id.blank? or @@apphoshies_configuration.username.blank? or @@apphoshies_configuration.api_key.blank?
6
+ raise ApphoshiesClient::MissingCredentialsException, 'Username, API Key and App Id required!'
7
+ end
8
+
9
+ return find(query_symbol, :params => {:app_id => @@apphoshies_configuration.app_id}) if query_symbol.is_a?(String)
10
+ default_options = {:app_id => @@apphoshies_configuration.app_id, :limit => 100}
11
+ find(:all, :params => default_options.merge(options))
12
+ end
13
+
14
+ def self.all(options = {})
15
+ get(:all, options)
16
+ end
17
+
18
+ def self.find_one(id); get(id); end
19
+
20
+ def self.find_by_application_client_key(application_client_key, options = {})
21
+ default_options = {:app_id => @@apphoshies_configuration.app_id, :application_client_key => application_client_key}
22
+ get(:all, options)
23
+ end
24
+
25
+ def self.find_by_datasource(datasource, options = {})
26
+ get(:all, options.merge(:datasource => datasource)) if datasource
27
+ end
28
+
29
+ def self.reload_http_headers
30
+ headers['APH_USERNAME'] = @@apphoshies_configuration.username
31
+ headers['APH_API_KEY'] = @@apphoshies_configuration.api_key
32
+ end
33
+ end
@@ -20,7 +20,7 @@ class ApphoshiesClient::Configuration
20
20
  puts "Using config in your home directory"
21
21
  @config = YAML.load(File.read("#{ENV['HOME']}/.apphoshies.yml"))
22
22
  rescue Errno::ENOENT
23
- puts ">>> apphoshies.yml expected in current directory or ~/.apphoshies.yml"
23
+ raise ApphoshiesClient::MissingConfigurationException, "apphoshies.yml expected in current directory or ~/.apphoshies.yml"
24
24
  end
25
25
  end
26
26
  end
@@ -0,0 +1,7 @@
1
+ class ApphoshiesClient::ContentItem < ApphoshiesClient::Document
2
+ self.element_name = "document"
3
+
4
+ def self.all(options = {})
5
+ find_by_datasource('content_items', options)
6
+ end
7
+ end
@@ -1,13 +1,15 @@
1
- class ApphoshiesClient::DeviceToken < ActiveResource::Base
2
- extend ClassMethods
3
-
1
+ class ApphoshiesClient::DeviceToken < ApphoshiesClient::Base
4
2
  self.site = @@apphoshies_configuration.site
5
3
  self.format = :json
6
4
  headers['APH_USERNAME'] = @@apphoshies_configuration.username
7
5
  headers['APH_API_KEY'] = @@apphoshies_configuration.api_key
8
-
6
+
9
7
  def self.find_by_application_client_key(application_client_key, options = {})
10
- default_options = {:app_id => @@apphoshies_configuration.app_id, :application_client_key => application_client_key}
11
- find(:all, :params => default_options.merge(options))
8
+ default_options = {:limit => 1, :application_client_key => application_client_key}
9
+ unless application_client_key.blank?
10
+ get(:all, default_options.merge(options))
11
+ else
12
+ raise ApphoshiesClient::MissingApplicationClientKeyException
13
+ end
12
14
  end
13
15
  end
@@ -1,30 +1,17 @@
1
- class ApphoshiesClient::Document < ActiveResource::Base
2
- extend ClassMethods
3
-
1
+ class ApphoshiesClient::Document < ApphoshiesClient::Base
4
2
  self.site = @@apphoshies_configuration.site
5
3
  self.format = :json
6
4
  headers['APH_USERNAME'] = @@apphoshies_configuration.username
7
5
  headers['APH_API_KEY'] = @@apphoshies_configuration.api_key
8
-
9
- def self.get(query_symbol, options = {})
10
- reload_http_headers
11
- return find(query_symbol, :params => {:app_id => @@apphoshies_configuration.app_id}) if query_symbol.is_a?(String)
12
- default_options = {:app_id => @@apphoshies_configuration.app_id, :limit => 100}
13
- find(:all, :params => default_options.merge(options))
14
- end
15
6
 
16
7
  def self.all(options = {})
17
- reload_http_headers
18
- get(:all, options)
8
+ if options and options[:datasource]
9
+ find_by_datasource(options[:datasource], options)
10
+ else
11
+ raise ApphoshiesClient::MissingDatasourceException, 'Please provide a datasource option!'
12
+ end
19
13
  end
20
14
 
21
- def self.find_by_datasource(datasource, options = {})
22
- reload_http_headers
23
- get(:all, options.merge(:datasource => datasource))
24
- end
25
-
26
- def self.find_one(id); get(id); end
27
-
28
15
  def get_value(key)
29
16
  if self.values
30
17
  v = self.values.select {|value_object| value_object.respond_to?(key.to_sym)}
@@ -36,9 +23,16 @@ class ApphoshiesClient::Document < ActiveResource::Base
36
23
  _values = self.values.collect {|v| v.attributes}
37
24
  if value.is_a?(String)
38
25
  _values << {key => value, "type" => value.class.name.to_s}
39
- # TODO check other types!
26
+ elsif value.is_a?(Fixnum)
27
+ _values << {key => value, "type" => 'Integer'}
28
+ elsif value.is_a?(Float)
29
+ _values << {key => value, "type" => 'Float'}
30
+ elsif value.is_a?(TrueClass) or value.is_a?(FalseClass)
31
+ _values << {key => value, "type" => 'Boolean'}
32
+ elsif value.is_a?(DateTime)
33
+ _values << {key => value, "type" => 'DateTime'}
40
34
  else
41
- raise "Value type not supported yet!"
35
+ raise ApphoshiesClient::ValueTypeNotSupportedException
42
36
  end
43
37
  self.values = _values
44
38
  end
@@ -54,10 +48,4 @@ class ApphoshiesClient::Document < ActiveResource::Base
54
48
  return nil
55
49
  end
56
50
  end
57
-
58
- private
59
- def self.reload_http_headers
60
- headers['APH_USERNAME'] = @@apphoshies_configuration.username
61
- headers['APH_API_KEY'] = @@apphoshies_configuration.api_key
62
- end
63
51
  end
@@ -0,0 +1,5 @@
1
+ class ApphoshiesClient::MissingCredentialsException < Exception; end
2
+ class ApphoshiesClient::MissingApplicationClientKeyException < Exception; end
3
+ class ApphoshiesClient::MissingConfigurationException < Exception; end
4
+ class ApphoshiesClient::MissingDatasourceException < Exception; end
5
+ class ApphoshiesClient::ValueTypeNotSupportedException < Exception; end
@@ -1,33 +1,19 @@
1
- class ApphoshiesClient::FileUpload < ActiveResource::Base
2
- extend ClassMethods
3
-
1
+ class ApphoshiesClient::FileUpload < ApphoshiesClient::Base
4
2
  self.site = @@apphoshies_configuration.site
5
3
  self.format = :json
6
4
  headers['APH_USERNAME'] = @@apphoshies_configuration.username
7
5
  headers['APH_API_KEY'] = @@apphoshies_configuration.api_key
8
6
 
9
7
  def url
10
- "https://service.apphoshies.com/file_uploads/#{self.id}"
8
+ "#{@@apphoshies_configuration.site}/file_uploads/#{self.id}"
11
9
  end
12
10
 
13
11
  def self.find_by_application_client_key(application_client_key, options = {})
14
- reload_http_headers
15
- default_options = {:app_id => @@apphoshies_configuration.app_id, :application_client_key => application_client_key}
16
- find(:all, :params => default_options.merge(options))
17
- end
18
-
19
- def self.find_one(id); get(id); end
20
-
21
- def self.get(query_symbol, options = {})
22
- reload_http_headers
23
- return find(query_symbol, :params => {:app_id => @@apphoshies_configuration.app_id}) if query_symbol.is_a?(String)
24
- default_options = {:app_id => @@apphoshies_configuration.app_id, :limit => 100}
25
- find(:all, :params => default_options.merge(options))
26
- end
27
-
28
- private
29
- def self.reload_http_headers
30
- headers['APH_USERNAME'] = @@apphoshies_configuration.username
31
- headers['APH_API_KEY'] = @@apphoshies_configuration.api_key
12
+ default_options = {:limit => 100, :application_client_key => application_client_key}
13
+ unless application_client_key.blank?
14
+ get(:all, default_options.merge(options))
15
+ else
16
+ raise ApphoshiesClient::MissingApplicationClientKeyException
17
+ end
32
18
  end
33
19
  end
@@ -1,13 +1,15 @@
1
- class ApphoshiesClient::Message < ActiveResource::Base
2
- extend ClassMethods
3
-
1
+ class ApphoshiesClient::Message < ApphoshiesClient::Base
4
2
  self.site = @@apphoshies_configuration.site
5
3
  self.format = :json
6
4
  headers['APH_USERNAME'] = @@apphoshies_configuration.username
7
5
  headers['APH_API_KEY'] = @@apphoshies_configuration.api_key
8
6
 
9
7
  def self.find_by_application_client_key(application_client_key, options = {})
10
- default_options = {:app_id => @@apphoshies_configuration.app_id, :application_client_key => application_client_key}
11
- find(:all, :params => default_options.merge(options))
8
+ default_options = {:limit => 100, :last_check_at => 1440, :application_client_key => application_client_key}
9
+ unless application_client_key.blank?
10
+ get(:all, default_options.merge(options))
11
+ else
12
+ raise ApphoshiesClient::MissingApplicationClientKeyException
13
+ end
12
14
  end
13
15
  end
@@ -0,0 +1,7 @@
1
+ class ApphoshiesClient::TrackingItem < ApphoshiesClient::Document
2
+ self.element_name = "document"
3
+
4
+ def self.all(options = {})
5
+ find_by_datasource('tracking_items', options)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class ApphoshiesClient::User < ApphoshiesClient::Document
2
+ self.element_name = "document"
3
+
4
+ def self.all(options = {})
5
+ find_by_datasource('users', options)
6
+ end
7
+ end
data/script/console CHANGED
@@ -7,4 +7,5 @@ libs = " -r irb/completion"
7
7
  # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
8
  libs << " -r #{File.dirname(__FILE__) + '/../lib/apphoshies_client.rb'}"
9
9
  puts "Loading apphoshies_client gem"
10
- exec "#{irb} #{libs} --simple-prompt"
10
+ exec "#{irb} #{libs} --simple-prompt"
11
+
@@ -1,11 +1,10 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestApphoshiesClient < Test::Unit::TestCase
4
-
5
- def setup
6
- end
7
-
8
- def test_truth
9
- assert true
10
- end
11
- end
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestApphoshiesClient < Test::Unit::TestCase
4
+ def setup
5
+ end
6
+
7
+ def test_truth
8
+ assert true
9
+ end
10
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apphoshies-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 0.4.0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Oliver Kiessler
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-17 00:00:00 +01:00
18
+ date: 2010-12-21 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -66,7 +66,10 @@ dependencies:
66
66
  version: 2.6.1
67
67
  type: :development
68
68
  version_requirements: *id003
69
- description: The App Hoshies infrastructure is based on REST Webservices. For your convenience client frameworks are provided to interact with your data.
69
+ description: |-
70
+ The App Hoshies App Data Cloud is based on REST Webservices. For your convenience client frameworks are provided to interact with your data (iOS/Android/Ruby). At the moment the App Data Cloud is in private beta mode. Please contact support (at) apphoshies (dot) com if you want to try it out.
71
+
72
+ Please visit http://apphoshies.com/service for more information.
70
73
  email:
71
74
  - kiessler@apphoshies.com
72
75
  executables: []
@@ -84,10 +87,14 @@ files:
84
87
  - README.rdoc
85
88
  - Rakefile
86
89
  - lib/apphoshies_client.rb
87
- - lib/apphoshies_client/class_methods.rb
88
90
  - lib/apphoshies_client/configuration.rb
91
+ - lib/apphoshies_client/exceptions.rb
92
+ - lib/apphoshies_client/base.rb
89
93
  - lib/apphoshies_client/device_token.rb
90
94
  - lib/apphoshies_client/document.rb
95
+ - lib/apphoshies_client/content_item.rb
96
+ - lib/apphoshies_client/tracking_item.rb
97
+ - lib/apphoshies_client/user.rb
91
98
  - lib/apphoshies_client/message.rb
92
99
  - lib/apphoshies_client/file_upload.rb
93
100
  - script/console
@@ -129,7 +136,7 @@ rubyforge_project: apphoshies-ruby-client
129
136
  rubygems_version: 1.3.7
130
137
  signing_key:
131
138
  specification_version: 3
132
- summary: The App Hoshies infrastructure is based on REST Webservices
139
+ summary: The App Hoshies App Data Cloud is based on REST Webservices
133
140
  test_files:
134
141
  - test/test_apphoshies_client.rb
135
142
  - test/test_helper.rb
@@ -1,2 +0,0 @@
1
- module ClassMethods
2
- end