Class: Orion::Geo

Inherits:
Object
  • Object
show all
Defined in:
lib/orion/geo/geo.rb

Instance Method Summary collapse

Constructor Details

#initializeGeo

Returns a new instance of Geo.



7
8
9
10
# File 'lib/orion/geo/geo.rb', line 7

def initialize
  config = Orion::Config::load_config('http://192.168.99.100:32769')
  @url = config[:orion_url]
end

Instance Method Details

#delete(type, id) ⇒ Object

type = type of data E.g: ‘City’ id = id of the object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/orion/geo/geo.rb', line 83

def delete(type, id)
  action = '/ngsi10/updateContext'

  options = {
    body: {
      contextElements: [
        {
          type: type,
          isPattern: "false",
          id: id
        }
      ]
    }.to_json,
    headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
  }

  HTTParty.post(@url + action, options)
end

#pull(type, type_area, array_point) ⇒ Object

type = type of data E.g: ‘City’ type_area = ‘circle’ || ‘polygon’

- polygon: array_point = ['lat, long','lat, long','lat, long'] ----- infinite number of points
- circle: array_point = ['lat, long, radius'] ----- radius in meters


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/orion/geo/geo.rb', line 54

def pull(type, type_area, array_point)
  action = '/ngsi10/queryContext'

  options = {
      body: {
      entities: [
        {
          type: type,
          isPattern: "true",
          id: ".*"
        }
      ],
      restriction: {
        scopes: [
          {
            type: "FIWARE::Location",
            value: get_area(type_area, array_point)
          }
        ]
      }
    }.to_json,
    headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
  }

  HTTParty.post(@url + action, options)
end

#push(type, id, long, lat) ⇒ Object

type = type of data E.g: ‘City’ id = id of the element long = Longitude lat = latitude



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/orion/geo/geo.rb', line 16

def push(type,id,long,lat)
  action = '/ngsi10/updateContext'

  options = {
      body: {
          contextElements: [
            {
              type: type,
              isPattern: "false",
              id: id,
              attributes: [
              {
                name: "position",
                type: "coords",
                value: "#{lat}, #{long}",
                metadatas: [
                  {
                    name: "location",
                    type: "string",
                    value: "WSG84"
                  }
                ]
              }
            ]
          }
          ],
          updateAction: "APPEND"
        }.to_json,
      headers: { 'Content-Type' => 'application/json' }
      }

  HTTParty.post(@url + action, options)
end