xively-rb 0.2.09

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/.gitignore +13 -0
  2. data/.rbenv-version +1 -0
  3. data/.rspec +2 -0
  4. data/.rvmrc +1 -0
  5. data/.travis.yml +7 -0
  6. data/CHANGELOG.md +91 -0
  7. data/CONTRIBUTING.md +95 -0
  8. data/Gemfile +15 -0
  9. data/LICENSE.md +13 -0
  10. data/README.md +10 -0
  11. data/Rakefile +25 -0
  12. data/ci/build_hudson.sh +24 -0
  13. data/init.rb +2 -0
  14. data/lib/xively-rb.rb +44 -0
  15. data/lib/xively-rb/array_extensions.rb +6 -0
  16. data/lib/xively-rb/base.rb +52 -0
  17. data/lib/xively-rb/base/instance_methods.rb +28 -0
  18. data/lib/xively-rb/client.rb +43 -0
  19. data/lib/xively-rb/datapoint.rb +72 -0
  20. data/lib/xively-rb/datastream.rb +127 -0
  21. data/lib/xively-rb/exceptions.rb +5 -0
  22. data/lib/xively-rb/feed.rb +109 -0
  23. data/lib/xively-rb/hash_extensions.rb +16 -0
  24. data/lib/xively-rb/helpers.rb +41 -0
  25. data/lib/xively-rb/key.rb +99 -0
  26. data/lib/xively-rb/nil_content.rb +15 -0
  27. data/lib/xively-rb/object_extensions.rb +6 -0
  28. data/lib/xively-rb/parsers/csv/datastream_defaults.rb +50 -0
  29. data/lib/xively-rb/parsers/csv/feed_defaults.rb +97 -0
  30. data/lib/xively-rb/parsers/defaults.rb +15 -0
  31. data/lib/xively-rb/parsers/json/datapoint_defaults.rb +16 -0
  32. data/lib/xively-rb/parsers/json/datastream_defaults.rb +58 -0
  33. data/lib/xively-rb/parsers/json/feed_defaults.rb +114 -0
  34. data/lib/xively-rb/parsers/json/key_defaults.rb +20 -0
  35. data/lib/xively-rb/parsers/json/search_result_defaults.rb +24 -0
  36. data/lib/xively-rb/parsers/json/trigger_defaults.rb +16 -0
  37. data/lib/xively-rb/parsers/xml/datapoint_defaults.rb +27 -0
  38. data/lib/xively-rb/parsers/xml/datastream_defaults.rb +53 -0
  39. data/lib/xively-rb/parsers/xml/errors.rb +7 -0
  40. data/lib/xively-rb/parsers/xml/feed_defaults.rb +83 -0
  41. data/lib/xively-rb/parsers/xml/helpers.rb +116 -0
  42. data/lib/xively-rb/parsers/xml/key_defaults.rb +46 -0
  43. data/lib/xively-rb/parsers/xml/trigger_defaults.rb +28 -0
  44. data/lib/xively-rb/permission.rb +67 -0
  45. data/lib/xively-rb/resource.rb +43 -0
  46. data/lib/xively-rb/search_result.rb +68 -0
  47. data/lib/xively-rb/string_extensions.rb +6 -0
  48. data/lib/xively-rb/templates/csv/datapoint_defaults.rb +22 -0
  49. data/lib/xively-rb/templates/csv/datastream_defaults.rb +43 -0
  50. data/lib/xively-rb/templates/csv/feed_defaults.rb +47 -0
  51. data/lib/xively-rb/templates/defaults.rb +14 -0
  52. data/lib/xively-rb/templates/json/datapoint_defaults.rb +15 -0
  53. data/lib/xively-rb/templates/json/datastream_defaults.rb +61 -0
  54. data/lib/xively-rb/templates/json/feed_defaults.rb +90 -0
  55. data/lib/xively-rb/templates/json/key_defaults.rb +39 -0
  56. data/lib/xively-rb/templates/json/search_result_defaults.rb +42 -0
  57. data/lib/xively-rb/templates/json/trigger_defaults.rb +21 -0
  58. data/lib/xively-rb/templates/xml/datapoint_defaults.rb +25 -0
  59. data/lib/xively-rb/templates/xml/datastream_defaults.rb +66 -0
  60. data/lib/xively-rb/templates/xml/feed_defaults.rb +112 -0
  61. data/lib/xively-rb/templates/xml/search_result_defaults.rb +118 -0
  62. data/lib/xively-rb/templates/xml_headers.rb +17 -0
  63. data/lib/xively-rb/trigger.rb +66 -0
  64. data/lib/xively-rb/validations.rb +9 -0
  65. data/lib/xively-rb/version.rb +3 -0
  66. data/spec/fixtures/models.rb +81 -0
  67. data/spec/spec_helper.rb +29 -0
  68. data/spec/support/contain_datapoint_eeml_matcher.rb +16 -0
  69. data/spec/support/contain_datastream_eeml_matcher.rb +60 -0
  70. data/spec/support/contain_feed_eeml_matcher.rb +98 -0
  71. data/spec/support/datapoint_helper.rb +53 -0
  72. data/spec/support/datastream_helper.rb +324 -0
  73. data/spec/support/describe_eeml_matcher.rb +23 -0
  74. data/spec/support/feed_helper.rb +783 -0
  75. data/spec/support/fully_represent_datapoint_matcher.rb +30 -0
  76. data/spec/support/fully_represent_datastream_matcher.rb +96 -0
  77. data/spec/support/fully_represent_feed_matcher.rb +234 -0
  78. data/spec/support/fully_represent_key_matcher.rb +74 -0
  79. data/spec/support/fully_represent_search_result_matcher.rb +67 -0
  80. data/spec/support/fully_represent_trigger_matcher.rb +29 -0
  81. data/spec/support/key_helper.rb +74 -0
  82. data/spec/support/search_result_helper.rb +252 -0
  83. data/spec/support/trigger_helper.rb +51 -0
  84. data/spec/xively-rb/array_extensions_spec.rb +9 -0
  85. data/spec/xively-rb/base/instance_methods_spec.rb +109 -0
  86. data/spec/xively-rb/base_spec.rb +56 -0
  87. data/spec/xively-rb/client_spec.rb +51 -0
  88. data/spec/xively-rb/datapoint_spec.rb +187 -0
  89. data/spec/xively-rb/datastream_spec.rb +344 -0
  90. data/spec/xively-rb/feed_spec.rb +341 -0
  91. data/spec/xively-rb/hash_extensions_spec.rb +20 -0
  92. data/spec/xively-rb/helpers_spec.rb +56 -0
  93. data/spec/xively-rb/key_spec.rb +198 -0
  94. data/spec/xively-rb/parsers/csv/datastream_defaults_spec.rb +110 -0
  95. data/spec/xively-rb/parsers/csv/feed_defaults_spec.rb +234 -0
  96. data/spec/xively-rb/parsers/json/datapoint_defaults_spec.rb +21 -0
  97. data/spec/xively-rb/parsers/json/datastream_defaults_spec.rb +105 -0
  98. data/spec/xively-rb/parsers/json/feed_defaults_spec.rb +45 -0
  99. data/spec/xively-rb/parsers/json/key_defaults_spec.rb +14 -0
  100. data/spec/xively-rb/parsers/json/search_result_defaults_spec.rb +18 -0
  101. data/spec/xively-rb/parsers/json/trigger_defaults_spec.rb +22 -0
  102. data/spec/xively-rb/parsers/xml/datapoint_defaults_spec.rb +19 -0
  103. data/spec/xively-rb/parsers/xml/datastream_defaults_spec.rb +148 -0
  104. data/spec/xively-rb/parsers/xml/feed_defaults_spec.rb +254 -0
  105. data/spec/xively-rb/parsers/xml/key_defaults_spec.rb +22 -0
  106. data/spec/xively-rb/parsers/xml/trigger_defaults_spec.rb +22 -0
  107. data/spec/xively-rb/search_result_spec.rb +257 -0
  108. data/spec/xively-rb/string_extensions_spec.rb +12 -0
  109. data/spec/xively-rb/templates/csv/datapoint_defaults_spec.rb +41 -0
  110. data/spec/xively-rb/templates/csv/datastream_defaults_spec.rb +131 -0
  111. data/spec/xively-rb/templates/csv/feed_defaults_spec.rb +78 -0
  112. data/spec/xively-rb/templates/json/datapoint_defaults_spec.rb +14 -0
  113. data/spec/xively-rb/templates/json/datastream_defaults_spec.rb +170 -0
  114. data/spec/xively-rb/templates/json/feed_defaults_spec.rb +399 -0
  115. data/spec/xively-rb/templates/json/key_defaults_spec.rb +29 -0
  116. data/spec/xively-rb/templates/json/search_result_defaults_spec.rb +37 -0
  117. data/spec/xively-rb/templates/json/trigger_defaults_spec.rb +19 -0
  118. data/spec/xively-rb/templates/xml/datapoint_defaults_spec.rb +14 -0
  119. data/spec/xively-rb/templates/xml/datastream_defaults_spec.rb +113 -0
  120. data/spec/xively-rb/templates/xml/feed_defaults_spec.rb +131 -0
  121. data/spec/xively-rb/templates/xml/search_result_defaults_spec.rb +44 -0
  122. data/spec/xively-rb/trigger_spec.rb +157 -0
  123. data/xively-rb.gemspec +41 -0
  124. metadata +333 -0
@@ -0,0 +1,13 @@
1
+ .DS_Store
2
+ .bundle/*
3
+ *.swp
4
+ *.swo
5
+ Gemfile.lock
6
+ .gem/*
7
+ build_artefacts/*
8
+ coverage/*
9
+ debug.log
10
+ test.sqlite3.db
11
+ *.gem
12
+ *.orig
13
+ vendor/bundle
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p392
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format documentation
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create 1.8.7-p249@xively-rb
@@ -0,0 +1,7 @@
1
+ bundler_args: --without development
2
+ language: ruby
3
+ env: COVERAGE=on
4
+ script: bundle exec rspec spec
5
+ rvm:
6
+ - 1.9.2
7
+ - 1.9.3
@@ -0,0 +1,91 @@
1
+ # Changelog
2
+
3
+ ## 0.1.11
4
+ * Keys always have a root node of 'keys'
5
+
6
+ ## 0.1.10
7
+ * Adding label field to Keys
8
+ * should pass options through to Key#as_json
9
+ * Clearing up some confusion with trigger/key parsers
10
+ * Improving the Key.to_json error handling
11
+
12
+ ## 0.1.09
13
+ * Adding Key model for api keys, XML/JSON parsers, and JSON template
14
+
15
+ ## 0.1.08
16
+ * Rewrote tag string parser
17
+
18
+ ## 0.1.07
19
+ * Adding some validations on feed_id for datastreams and datapoints
20
+
21
+ ## 0.1.06
22
+ * Feeds should invalidate with duplicate datastream ids or invalid datastreams
23
+ * Fixed a bug in Template#method_missing
24
+
25
+ ## 0.1.05
26
+ * Added CSV feed parsing with autodetection of version
27
+
28
+ ## 0.1.04
29
+ * Added user node parsers to Feed eeml 0.5.1 and json 1.0.0
30
+
31
+ ## 0.1.03
32
+ * Added owner_login and owner_user_level to Feed
33
+ * user node added to json 1.0.0 and eeml 0.5.1 templates for Feed
34
+
35
+ ## 0.1.02
36
+ * Bug fix release
37
+ * Handling empty (nil) datastreams in json 1.0.0 (feeds and search results)
38
+
39
+ ## 0.1.01
40
+ * Major release that
41
+ * Eliminates requirement for ActiveSupport / ActiveModel
42
+ * PachubeDataFormat objects have basic validation
43
+
44
+ ## 0.0.3
45
+ * Ignore nil tags with json parsers
46
+ * Added templates for datastream level eeml 005 and 0.5.1
47
+ * Added templates for EEML 005 and 0.5.1 (v1 / v2)
48
+ * Eeml 0.5.1 and 5 datastream parser
49
+ * Eeml 0.5.1 and 5 feed parser
50
+ * Providing as_pachube_xml on AR records
51
+ * Adding creator to default xml parsers
52
+ * encode xml in utf-8
53
+ * Adding feed_id and feed_creator onto datastream (used by xml)
54
+ * Creator is always http://www.haque.co.uk in v1 xml
55
+ * Creator always http://www.haque.co.uk in v1 templates
56
+ * First pass at a Datapoint model w/ parsers and templates
57
+ * Added datapoints to json parser
58
+ * Creating datapoint templates
59
+ * Templates append format onto feed url
60
+ * order of xml attributes
61
+ * Hash#delete_if_nil_value
62
+ * Completely ignore unit nodes in xml if no unit attributes present
63
+ * iso8601 shouldn't be to precision of v2 api ignore nil.iso8601 calls
64
+ * Allow excluding datastreams
65
+ * Hooking up datapoints into ActiveRecord
66
+ * Bug fix: Datapoint json template wasn't formatting time to iso8601(6)
67
+ * datapoint templates need no version as there is only one
68
+ * moving private node
69
+ * Hide min/max value nodes on eeml 0.5.1 templates
70
+ * Simplifying ActiveRecord hooks Updated documentation
71
+ * Datapoint templates should iso8601 at Feed json template datapoints in iso8601(6)
72
+ * Added json template for search results
73
+ * XML and JSON templates for search results
74
+ * Adding opensearch namespace and nodes
75
+ * Merge branch 'hotfix-0.0.2' into develop
76
+ * Incorporating hotfix changes into search results
77
+ * Restructure of lib
78
+ * Basic csv for datapoints (full and minimal)
79
+ * Basic csv for datastreams and feeds * V1 * V2 * V2 full
80
+ * Allows options to be passed to to_csv
81
+ * KICK: Keep it consistent knucklehead
82
+ * Datastream#to_csv shows datapoints * options[:both] will include datastream as first element * Will only show datastream if no datapoints * Will only show all datapoints if any
83
+ * Escaping csv cells properly
84
+ * Handling datapoints in feed#to_csv
85
+ * Adding depth option to datapoint#to_csv
86
+ * Adding depth option to datastream#to_csv
87
+ * Ignoring units in eeml if no attributes present
88
+ * Refactoring specs
89
+ * Handle empty tags in xml
90
+ * Ignore primary nodes in xml feed templates
91
+
@@ -0,0 +1,95 @@
1
+ Whether it's clarifying how to use them, requesting new features, finding bugs, or contributing to writing them yourself, the Xively libraries are completely open-source and always being updated, and we want to hear your thoughts.
2
+
3
+ Feel free to fork and improve this library any way you want. If you feel that the library benefits from your changes, please open a pull request and contribute back!
4
+
5
+
6
+ ## Getting Help with Using a Library
7
+ For discussion, questions, and help with implementation, we use [Stack Overflow](http://stackoverflow.com/questions/tagged/xively). Be sure to use a `xively` tag.
8
+
9
+ ## Requesting New Features
10
+ If you've got a feature request for this library, file it with the GitHub issue tracker. (You can find it on the Github page for each library, under the "Issues" tab.) We're always expanding our libraries, and would love to hear your ideas.
11
+
12
+ ## Submitting Bug Reports
13
+ If you find a problem with a library, whether you are stuck or want to address it yourself, first log it using the GitHub issue tracker. That way, we can take a look and let you know how best to proceed, and if work is already underway on this issue.
14
+
15
+ **Note:** The issue tracker is for *bugs* and *new features*, not help requests. For procedural questions - like help - see the above "Getting Help" section.
16
+
17
+ #### Reporting bugs effectively
18
+
19
+ Please include as much information as you have available. Where possible:
20
+ - your IDE software and library version (e.g. Visual Studio 2012, mbed Online IDE, Xively Java Lib 1.0)
21
+ - what device you were running the code on (e.g. iOS 5, Android 4.0, Arduino Uno)
22
+ - how you are connected to the web (e.g. Gainspan wireless module, Ethernet)
23
+ - and any more detail you have (e.g. what are the underlying versions of software stack)
24
+
25
+ Mention very precisely what went wrong. For example, instead of "I can't add a datapoint", it is more helpful to say "the library returned an error 'X' when I tried datapoint.upload()". What did you expect to happen? What happened instead? Describe the exact steps you could take to recreate it.
26
+
27
+
28
+ ## Contributing to Xively Libraries
29
+ If you see an improvement that you can make to a library, bring it on! All of our libraries are open-source and constantly improving, so take a look at our guidelines below and send in your contribution.
30
+
31
+ ### Include Tests
32
+ All of our libraries are set up to be tested by Travis CI, with full-coverage unit tests, and integration tests where possible. If you are going to contribute, please ensure that your contributions can be tested as well. If you need help with this, let us know!
33
+
34
+ ### Use Pull Requests
35
+ If you know exactly how to implement the feature being suggested or fix the bug
36
+ being reported, please open a pull request instead of an issue. Pull requests are easier than
37
+ patches or inline code blocks for discussing and merging the changes.
38
+
39
+ ### Contributing (Step-by-step)
40
+
41
+ 1) Clone the Repo of the library you want to contribute to:
42
+ ```
43
+ git clone git://github.com/xively/xively-rb.git
44
+ ```
45
+ 2) Create a new Branch, named for the feature you're addressing or adding:
46
+ ```
47
+ cd xively-rb
48
+ git checkout -b new_feature_branch
49
+ ```
50
+ 3) Code:
51
+
52
+ Do what you do best here! Follow these guidelines, and be mindful of how your change will impact the whole of the library:
53
+ - write with testing in mind (and write tests!)
54
+ - keep the transport layer of a library (e.g. TCP/HTTP) separate from the Xively layer (e.g. Xively Feed object)
55
+ - make sure it won't break anything that relied on a previous version
56
+ - check to see if documentation updates are needed
57
+
58
+ 4) Rebase your commits
59
+
60
+ Many fixes require a multitude of commits, but when submitting a pull request, we'd prefer if you'd squash them into a single commit for readability:
61
+ ```
62
+ git remote add upstream https://github.com/xively/xively-rb
63
+ git fetch upstream
64
+ git checkout new_feature_branch
65
+ git rebase upstream/master
66
+ git rebase -i
67
+ ```
68
+ Choose 'squash' for all of your commits except the first one. Edit the commit message to describe the whole of your contribution and changes.
69
+ ```
70
+ git push origin new_feature_branch -f
71
+ git checkout master
72
+ git pull --rebase
73
+ ```
74
+
75
+ 5) Issue a Pull Request
76
+
77
+ First, push your rebased single commit to your remote fork of the Xively library
78
+ ```
79
+ git remote add mine git@github.com:<your user name>/discourse.git
80
+ git push mine new_feature_branch
81
+ ```
82
+ Then:
83
+ - Navigate to the repository you just pushed to (e.g. https://github.com/your-user-name/xively-rb)
84
+ - Click "Pull Request"
85
+ - Select your branch name (new_feature_branch) in the branch field
86
+ - Click "Update Commit Range"
87
+ - Ensure the changes you introduced are included in the "Commits" and "Files Changed" tabs
88
+ - Fill in some details about your potential contribution including a meaningful title
89
+ - Click "Send pull request".
90
+
91
+ Once these steps are done, we'll take a look and get back to you!
92
+
93
+ ###Responding to Feedback
94
+
95
+ The team may recommend adjustments to your code, and this is perfectly normal. Part of interacting with a healthy open-source community requires you to be open to learning new techniques and strategies; don't get discouraged! Remember: if the team suggest changes to your code, they care enough about your work that they want to include it, and hope that you can assist by implementing those revisions on your own.
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Gem dependencies specified in xively-rb.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "rake"
8
+ gem "debugger", :platforms => [:ruby_19]
9
+ end
10
+
11
+ group :test do
12
+ gem "rspec"
13
+ gem "simplecov"
14
+ gem "webmock"
15
+ end
@@ -0,0 +1,13 @@
1
+ ###This library is Open Source, under the BSD 3-Clause license.
2
+
3
+ Copyright (c) 2013, LogMeIn Inc.
4
+
5
+ All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11
+ 3. Neither the names of LogMeIn, Inc., nor Xively Ltd., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOGMEIN, INC. OR XIVELY LTD. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,10 @@
1
+ [![Build Status](https://secure.travis-ci.org/xively/xively-rb.png)](http://travis-ci.org/xively/xively-rb)
2
+
3
+ ## Xively gem
4
+
5
+ Use this gem if you would like to convert between Xively data formats or represent Xively objects in Ruby.
6
+ You can also interact with the Xively REST API using this gem.
7
+
8
+ ### Documentation
9
+
10
+ Documentation can be found on the [wiki](https://github.com/xively/xively-rb/wiki/Documentation).
@@ -0,0 +1,25 @@
1
+ require 'bundler/setup'
2
+
3
+ #require 'rake/testtask'
4
+ require 'rake/clean'
5
+ require 'rake/task'
6
+ require "rspec/core/rake_task"
7
+
8
+ CLEAN.include('pkg')
9
+ CLEAN.include('coverage')
10
+ CLOBBER.include('html')
11
+
12
+ Bundler::GemHelper.install_tasks
13
+
14
+ task :default => :spec
15
+
16
+ # run tests before building
17
+ task :build => :spec
18
+
19
+ namespace :spec do
20
+ desc "Run all specs tagged with :focus => true"
21
+ RSpec::Core::RakeTask.new(:focus) do |t|
22
+ t.rspec_opts = "--tag focus"
23
+ t.verbose = true
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+ set -u
5
+ set -x
6
+ #TODO: script the installation of the pre-reqs: sqlite3
7
+ #sudo apt-get install sqlite3 libsqlite3-dev libsqlite3-ruby
8
+
9
+ outdir='build_artefacts'
10
+ rm -rf $outdir
11
+ mkdir -p $outdir
12
+
13
+ echo "started build script $0 in `$outdir` at `date`"
14
+
15
+ show_platform.sh > $outdir/platform.txt 2>&1 || true
16
+
17
+ echo "Running custom build.sh - install bundle, rake"
18
+ bundle --path=.gem/
19
+ set +e
20
+ bundle exec rake rcov > $outdir/testtask.log
21
+ spec_rc=$?
22
+ set -e
23
+
24
+ exit $spec_rc
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'lib/xively-rb'
2
+
@@ -0,0 +1,44 @@
1
+ require 'nokogiri'
2
+ require 'multi_json'
3
+ require 'multi_xml'
4
+
5
+ $:.unshift(File.dirname(File.expand_path(__FILE__)))
6
+
7
+ $KCODE = 'u' if RUBY_VERSION.to_f < 1.9
8
+
9
+ require 'xively-rb/helpers'
10
+ require 'xively-rb/base'
11
+ require 'xively-rb/validations'
12
+ require 'xively-rb/object_extensions'
13
+ require 'xively-rb/nil_content'
14
+ require 'xively-rb/exceptions'
15
+ require 'xively-rb/string_extensions'
16
+ require 'xively-rb/array_extensions'
17
+ require 'xively-rb/hash_extensions'
18
+ require 'xively-rb/templates/defaults'
19
+ require 'xively-rb/parsers/defaults'
20
+ require 'xively-rb/feed'
21
+ require 'xively-rb/datastream'
22
+ require 'xively-rb/datapoint'
23
+ require 'xively-rb/search_result'
24
+ require 'xively-rb/trigger'
25
+ require 'xively-rb/key'
26
+ require 'xively-rb/permission'
27
+ require 'xively-rb/resource'
28
+
29
+ require 'xively-rb/client'
30
+
31
+ if defined?(JRUBY_VERSION)
32
+ MultiXml.parser = :nokogiri
33
+ else
34
+ MultiXml.parser = :ox
35
+ end
36
+
37
+ if RUBY_VERSION.to_f < 1.9
38
+ require 'fastercsv'
39
+ Xively::CSV = FasterCSV
40
+ else
41
+ require 'csv'
42
+ Xively::CSV = CSV
43
+ end
44
+
@@ -0,0 +1,6 @@
1
+ class Array
2
+ def split(pattern = nil, limit = nil)
3
+ self
4
+ end
5
+ end
6
+
@@ -0,0 +1,52 @@
1
+ require 'xively-rb/base/instance_methods'
2
+
3
+ module Xively
4
+ # Provide an interface for your model objects by extending this module:
5
+ # extend Xively::Base
6
+ #
7
+ # This provides the following configuration class method:
8
+ # is_xively:
9
+ # - specifies that this model represents all or part of a Xively feed
10
+ module Base
11
+
12
+ # Provides methods for converting between the different Xively API data formats
13
+ # An example for a model representing a Xively feed:
14
+ #
15
+ # is_xively :feed
16
+ #
17
+ # A datastream
18
+ #
19
+ # is_xively :datastream
20
+ #
21
+ # To specify custom field mappings or map methods onto a field
22
+ #
23
+ # is_xively :feed, {:title => :my_custom_instance_method, :status => :determine_feed_state}
24
+ #
25
+ def is_xively(klass, options = {})
26
+ @options = options
27
+ case klass
28
+ when :feed
29
+ @xively_class = Xively::Feed
30
+ when :datastream
31
+ @xively_class = Xively::Datastream
32
+ when :datapoint
33
+ @xively_class = Xively::Datapoint
34
+ else
35
+ @xively_class = nil
36
+ end
37
+
38
+ class << self
39
+ def xively_mappings
40
+ @options
41
+ end
42
+
43
+ def xively_class
44
+ @xively_class
45
+ end
46
+ end
47
+
48
+ send :include, Xively::Base::InstanceMethods
49
+ end
50
+ end
51
+ end
52
+
@@ -0,0 +1,28 @@
1
+ module Xively
2
+ module Base
3
+ module InstanceMethods
4
+
5
+ # Converts a model that extends Xively::Base into it's equivalent Xively object
6
+ # this can then be used to convert into xml, json or csv
7
+ def to_xively
8
+ attributes = {}
9
+ self.class.xively_class::ALLOWED_KEYS.each do |key|
10
+ attributes[key] = self.send(key) if self.respond_to?(key)
11
+ end
12
+ self.class.xively_class.new(attributes.merge(custom_xively_attributes))
13
+ end
14
+
15
+ protected
16
+
17
+ def custom_xively_attributes(options = {})
18
+ hash = {}
19
+ self.class.xively_mappings.each do |key, value|
20
+ hash[key.to_s] = self.send(value)
21
+ end
22
+ hash
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+