fiware-orion-geo 0.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 713492ae3468b92dfdf6096f89cc92bcfad2e602
4
- data.tar.gz: 550edceac9215673cca82a1e501f8d7b4d3271a3
3
+ metadata.gz: 1e0c615da80260fd517e1f4b8614ec017bfd60f5
4
+ data.tar.gz: 53f89816480b6cf7d7bfa059599d74a0ebc57921
5
5
  SHA512:
6
- metadata.gz: 3259d2117cef22cc4127fcc43038d03a91dd419227ad3b09335ae20a6d0abfaa678017249240d401204799cd22c5dc2d0cbb6062319a11bb9b6479abeffc9273
7
- data.tar.gz: c806c79835a57ecbd2673436fed671e89ce4127847914c5ca99f0f136600b369bc61ccb8a2007d57cbf9cf1f66b37b55023df4acef91acda1af3421895433949
6
+ metadata.gz: a781e93649a6b109a99d6523dd91d3156d6b6f25ee3d2a3a179fe3ed2cceb7526945a5e01cee597bb5155eda5828ecb85c25a71a4200f42f9ff24390b30bb4c0
7
+ data.tar.gz: 3e979fae91642efa440b1ea0f7f667f18b29406ef4c5e3db74eef2caf3d83f9ea184372507b01108085810a06a250dbb325f19e8817af44c4030eb180c3e0f07
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ he MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Nikolaï POSNER
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # fiware-orion-geo
2
+ Interface to dialog with Orion server from Fiware (Geolocalization)
3
+
4
+ # Config
5
+
6
+ Dependencies:
7
+ HTTPParty - https://rubygems.org/gems/httparty
8
+
9
+ To configure the gem create the file config/initializers/fiware_orion_config.rb and add the configuration of the client.
10
+
11
+ Example:
12
+
13
+ ```ruby
14
+ Rails.application.config.after_initialize do
15
+ ORION_SERVER_IP = {Your Orion server address} unless defined?(ORION_SERVER_IP)
16
+
17
+ Orion::Config.load_config(ORION_SERVER_IP)
18
+ end
19
+ ```
20
+
21
+ # Installation
22
+
23
+ Add to your Gemfile:
24
+
25
+ `gem 'qq_client'`
26
+
27
+ Then bundle install
28
+
29
+ Or install it yourself as:
30
+
31
+ `$ gem install qq_client`
32
+
33
+ # Usage
34
+
35
+ * type = type of object stored E.g:'Cars', 'Houses', 'Fruits'... - String
36
+ * id = identifier of the object - String
37
+ * type_area = can be 'polygon' or 'circle' - String
38
+ * circle: array_point = ['lat', 'long', 'radius'] ----- radius in meters
39
+ * polygon: array_point = ['lat, long','lat, long','lat, long'] ----- infinite number of points
40
+
41
+
42
+ `Orion::Geo.new`
43
+
44
+ INSERT
45
+ `def push(type, id, long, lat)`
46
+
47
+ SELECT
48
+ `def pull(type, type_area, array_point)`
49
+
50
+ DELETE
51
+ `def delete(type, id)`
52
+
53
+ UPDATE = To update you have to delete the object then create a new one (REF: Fiware documentation)
54
+
55
+
56
+ # Contributing
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :spec
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'fiware-orion-geo'
3
+ s.version = '0.0.2'
4
+ s.date = '2014-08-03'
5
+ s.summary = "Interface for Orion server"
6
+ s.description = "Gives you the possibility to simply interfear with Orion server (from Fiware) to insert and retreive data based on geolocalisation"
7
+ s.authors = ["Nikolaï POSNER"]
8
+ s.email = 'nikoposner@gmail.com'
9
+ s.files = `git ls-files`.split($\)
10
+ s.homepage = 'http://rubygems.org/gems/fiware-orion-geo'
11
+ s.license = 'MIT'
12
+
13
+ s.add_development_dependency 'rspec', '~> 0'
14
+ s.add_runtime_dependency 'httparty', '~> 0'
15
+ end
@@ -1,5 +1,2 @@
1
- class FiwareOrionGeo
2
- def self.test
3
- puts 'test'
4
- end
5
- end
1
+ require 'orion/geo/geo'
2
+ require 'orion/config'
@@ -0,0 +1,43 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Orion
3
+ module Config
4
+
5
+ class << self
6
+ attr_reader :orion_url
7
+
8
+ def load_config(orion_url)
9
+ begin
10
+ filename = "/config/initializers/fiware_orion_config.rb"
11
+ # filename = "#{Rails.root}/config/initializers/fiware_orion_config.rb"
12
+ if self.check_config_file(filename)
13
+ require filename
14
+ @orion_url = (orion_url.nil?) ? ORION_SERVER_IP : orion_url
15
+ else
16
+ @orion_url = orion_url
17
+ puts @orion_url
18
+ end
19
+ {
20
+ orion_url: @orion_url,
21
+ }
22
+ rescue => e
23
+ puts e => e.message
24
+ end
25
+ end
26
+
27
+ def check_config_file(filename)
28
+ result = true
29
+ unless File.exist?(filename)
30
+ puts "|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
31
+ puts "|"
32
+ puts "Please configure orion_url in #{filename}."
33
+ puts "|"
34
+ puts "|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
35
+ result = false
36
+ end
37
+ result
38
+ end
39
+ end
40
+
41
+
42
+ end
43
+ end
@@ -0,0 +1,132 @@
1
+ require 'httparty'
2
+ require 'pp'
3
+
4
+ module Orion
5
+ class Geo
6
+
7
+ def initialize
8
+ config = Orion::Config::load_config('http://192.168.99.100:32769')
9
+ @url = config[:orion_url]
10
+ end
11
+
12
+ # type = type of data E.g: 'City'
13
+ # id = id of the element
14
+ # long = Longitude
15
+ # lat = latitude
16
+ def push(type,id,long,lat)
17
+ action = '/ngsi10/updateContext'
18
+
19
+ options = {
20
+ body: {
21
+ contextElements: [
22
+ {
23
+ type: type,
24
+ isPattern: "false",
25
+ id: id,
26
+ attributes: [
27
+ {
28
+ name: "position",
29
+ type: "coords",
30
+ value: "#{lat}, #{long}",
31
+ metadatas: [
32
+ {
33
+ name: "location",
34
+ type: "string",
35
+ value: "WSG84"
36
+ }
37
+ ]
38
+ }
39
+ ]
40
+ }
41
+ ],
42
+ updateAction: "APPEND"
43
+ }.to_json,
44
+ headers: { 'Content-Type' => 'application/json' }
45
+ }
46
+
47
+ HTTParty.post(@url + action, options)
48
+ end
49
+
50
+ # type = type of data E.g: 'City'
51
+ # type_area = 'circle' || 'polygon'
52
+ # - polygon: array_point = ['lat, long','lat, long','lat, long'] ----- infinite number of points
53
+ # - circle: array_point = ['lat, long, radius'] ----- radius in meters
54
+ def pull(type, type_area, array_point)
55
+ action = '/ngsi10/queryContext'
56
+
57
+ options = {
58
+ body: {
59
+ entities: [
60
+ {
61
+ type: type,
62
+ isPattern: "true",
63
+ id: ".*"
64
+ }
65
+ ],
66
+ restriction: {
67
+ scopes: [
68
+ {
69
+ type: "FIWARE::Location",
70
+ value: get_area(type_area, array_point)
71
+ }
72
+ ]
73
+ }
74
+ }.to_json,
75
+ headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
76
+ }
77
+
78
+ HTTParty.post(@url + action, options)
79
+ end
80
+
81
+ # type = type of data E.g: 'City'
82
+ # id = id of the object
83
+ def delete(type, id)
84
+ action = '/ngsi10/updateContext'
85
+
86
+ options = {
87
+ body: {
88
+ contextElements: [
89
+ {
90
+ type: type,
91
+ isPattern: "false",
92
+ id: id
93
+ }
94
+ ]
95
+ }.to_json,
96
+ headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
97
+ }
98
+
99
+ HTTParty.post(@url + action, options)
100
+ end
101
+
102
+ # type_area = 'circle' || 'polygon'
103
+ # - polygon: array_point = ['lat, long','lat, long','lat, long'] ----- infinite number of points
104
+ # - polygon: array_point = [lat, long, radius] ----- radius in meters
105
+ private
106
+ def get_area(type_area, array_point)
107
+ if type_area == 'circle'
108
+ area = {
109
+ circle: {
110
+ centerLatitude: array_point[0],
111
+ centerLongitude: array_point[1],
112
+ radius: array_point[2]
113
+ }
114
+ }
115
+ else
116
+ area = {
117
+ polygon: {
118
+ vertices:
119
+ array_point.map{ |c|
120
+ c = c.split(',')
121
+ {
122
+ latitude: c[0],
123
+ longitude: c[1]
124
+ }
125
+ }
126
+ }
127
+ }
128
+ end
129
+ area
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Endpoints Orion server' do
4
+
5
+ before(:each) do
6
+ @sut = Orion::Geo.new
7
+ end
8
+
9
+ describe 'Store geolocalisation data for object' do
10
+
11
+ context 'build a area' do
12
+ it 'should return circle' do
13
+ actual = @sut.instance_eval{get_area('circle', [2,3,2])}
14
+ expected = {circle: {centerLatitude: 2, centerLongitude: 3, radius: 2}}
15
+ expect(actual).to eq(expected)
16
+ end
17
+
18
+ it 'should return a polygon' do
19
+ actual = @sut.instance_eval{get_area('polygon', ['1,2','4,5','3,2'])}
20
+ expected = {polygon: {vertices: [{ latitude: '1', longitude: '2' }, { latitude: '4', longitude: '5' },{ latitude: '3', longitude: '2'}]}}
21
+ expect(actual).to eq(expected)
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,94 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ require 'fiware-orion-geo'
20
+
21
+
22
+ RSpec.configure do |config|
23
+ # rspec-expectations config goes here. You can use an alternate
24
+ # assertion/expectation library such as wrong or the stdlib/minitest
25
+ # assertions if you prefer.
26
+ config.expect_with :rspec do |expectations|
27
+ # This option will default to `true` in RSpec 4. It makes the `description`
28
+ # and `failure_message` of custom matchers include text for helper methods
29
+ # defined using `chain`, e.g.:
30
+ # be_bigger_than(2).and_smaller_than(4).description
31
+ # # => "be bigger than 2 and smaller than 4"
32
+ # ...rather than:
33
+ # # => "be bigger than 2"
34
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
+ end
36
+
37
+ # rspec-mocks config goes here. You can use an alternate test double
38
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
39
+ config.mock_with :rspec do |mocks|
40
+ # Prevents you from mocking or stubbing a method that does not exist on
41
+ # a real object. This is generally recommended, and will default to
42
+ # `true` in RSpec 4.
43
+ mocks.verify_partial_doubles = true
44
+ end
45
+
46
+ # The settings below are suggested to provide a good initial experience
47
+ # with RSpec, but feel free to customize to your heart's content.
48
+ =begin
49
+ # These two settings work together to allow you to limit a spec run
50
+ # to individual examples or groups you care about by tagging them with
51
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
52
+ # get run.
53
+ config.filter_run :focus
54
+ config.run_all_when_everything_filtered = true
55
+
56
+ # Limits the available syntax to the non-monkey patched syntax that is
57
+ # recommended. For more details, see:
58
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
59
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
60
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
61
+ config.disable_monkey_patching!
62
+
63
+ # This setting enables warnings. It's recommended, but in some cases may
64
+ # be too noisy due to issues in dependencies.
65
+ config.warnings = true
66
+
67
+ # Many RSpec users commonly either run the entire suite or an individual
68
+ # file, and it's useful to allow more verbose output when running an
69
+ # individual spec file.
70
+ if config.files_to_run.one?
71
+ # Use the documentation formatter for detailed output,
72
+ # unless a formatter has already been configured
73
+ # (e.g. via a command-line flag).
74
+ config.default_formatter = 'doc'
75
+ end
76
+
77
+ # Print the 10 slowest examples and example groups at the
78
+ # end of the spec run, to help surface which specs are running
79
+ # particularly slow.
80
+ config.profile_examples = 10
81
+
82
+ # Run specs in random order to surface order dependencies. If you find an
83
+ # order dependency and want to debug it, you can fix the order by providing
84
+ # the seed, which is printed after each run.
85
+ # --seed 1234
86
+ config.order = :random
87
+
88
+ # Seed global randomization in this process using the `--seed` CLI option.
89
+ # Setting this allows you to use `--seed` to deterministically reproduce
90
+ # test failures related to randomization by passing the same `--seed` value
91
+ # as the one that triggered the failure.
92
+ Kernel.srand config.seed
93
+ =end
94
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fiware-orion-geo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikolaï POSNER
@@ -10,6 +10,20 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: httparty
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -25,13 +39,23 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
27
41
  description: Gives you the possibility to simply interfear with Orion server (from
28
- Inpact) to insert and retreive data based on geolocalisation
42
+ Fiware) to insert and retreive data based on geolocalisation
29
43
  email: nikoposner@gmail.com
30
44
  executables: []
31
45
  extensions: []
32
46
  extra_rdoc_files: []
33
47
  files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - fiware-orion-geo.gemspec
34
54
  - lib/fiware-orion-geo.rb
55
+ - lib/orion/config.rb
56
+ - lib/orion/geo/geo.rb
57
+ - spec/fiware_orion_geo_spec.rb
58
+ - spec/spec_helper.rb
35
59
  homepage: http://rubygems.org/gems/fiware-orion-geo
36
60
  licenses:
37
61
  - MIT