fomo 0.0.3 → 0.0.4

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,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MjBmZjZhZmQ0MWVjMmJlYjhlZmFkZDU3NDdmYWVhYjdkN2QxZDBkMA==
5
- data.tar.gz: !binary |-
6
- Yzc5ZDU0Njk2N2QyZTA0YmQ0ZGJiYTFiMDc4YjRmODc4NjM4NTNmNg==
2
+ SHA1:
3
+ metadata.gz: dc89204a440d3cd0c46e52373f419460435cf29c
4
+ data.tar.gz: 50e3aa4a66b3cd43e1aa8990e38ef8a4dff26adc
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NGIwNmJhODlhZmFhODMxMmEwNjUwY2I1OGNjYmUwNDMyNmVhMWY4ZTg5ZjI1
10
- YTdjMWIyNDcwMmFiZjRiNjIwZWNmM2RhNTUzYjM3MWI4ODI4NmQ3NjQ3MWQy
11
- MTEzNzdhMWNlOGIyNGJhZDdiNmEwOTgxZmE4NGEyOTNkMzYyODc=
12
- data.tar.gz: !binary |-
13
- ZWE1NjQ5MzZiN2VkMTk4MmM2NTNhZThlMjM4ZDJlMGJkZjQ4Yzc3MTRmYWY2
14
- YThjMmRlODc0NjVjMDRhMzlmN2ZhMzllMDM2YjU1ZjQzYjY2MTRiMTc3NjM1
15
- NGYyNzY4ODUyNGRkZDM3NzZhMjJjNjZjN2Q4M2MxNmUwNTE2NzI=
6
+ metadata.gz: 248aff6e692930f3e7bded8770188f2eb764f7a8b6d36ea5dfbf287f10fade7d2bef6856baa846ca1c62ce1ef1193b78625f126af34aadde4b6d3c260cb9e249
7
+ data.tar.gz: 7416aca1119fc3cfdec8059256bc13e6f684d069490e3188b77d93890424d1cb30ea22d7f69e8cf80bd8aa55b0e622c805e7615aaec04e895cb353c3bdc7437a
data/lib/fomo.rb CHANGED
@@ -9,6 +9,8 @@ require 'json'
9
9
  require 'fomo_event_basic'
10
10
  require 'fomo_event'
11
11
  require 'fomo_delete_message_response'
12
+ require 'fomo_meta_data'
13
+ require 'fomo_events_with_meta'
12
14
 
13
15
  # Fomo Client is wrapper around official Fomo API (https://www.usefomo.com)
14
16
  class Fomo
@@ -26,6 +28,7 @@ class Fomo
26
28
  #
27
29
  def initialize (auth_token)
28
30
  @auth_token = auth_token
31
+ @version = '0.0.4'
29
32
  @endpoint = 'https://www.usefomo.com'
30
33
  end
31
34
 
@@ -48,10 +51,14 @@ class Fomo
48
51
 
49
52
  # Get events
50
53
  #
54
+ # Arguments:
55
+ # size: (Number) Page size
56
+ # page: (Number) Page number
57
+ #
51
58
  # Returns an array of FomoEvent objects.
52
59
  #
53
- def get_events
54
- response = make_request('/api/v1/applications/me/events', 'GET')
60
+ def get_events(size = 30, page = 1)
61
+ response = make_request('/api/v1/applications/me/events?per=' + size.to_s + '&page=' + page.to_s, 'GET')
55
62
  begin
56
63
  data = JSON.parse(response)
57
64
  list = []
@@ -64,6 +71,30 @@ class Fomo
64
71
  end
65
72
  end
66
73
 
74
+ # Get events with meta data
75
+ #
76
+ # Arguments:
77
+ # size: (Number) Page size
78
+ # page: (Number) Page number
79
+ #
80
+ # Returns an FomoEventsWithMeta object.
81
+ #
82
+ def get_events_with_meta(size = 30, page = 1)
83
+ response = make_request('/api/v1/applications/me/events?per=' + size.to_s + '&page=' + page.to_s + '&show_meta=true', 'GET')
84
+ begin
85
+ data = JSON.parse(response)
86
+
87
+ list = []
88
+ data['events'].each do |j|
89
+ list.push(FomoEvent.new(j['id'], j['created_at'], j['updated_at'], j['message'], j['link'], j['event_type_id'], j['event_type_tag'], j['url'], j['first_name'], j['city'], j['province'], j['country'], j['title'], j['image_url'], j['custom_event_fields_attributes']))
90
+ end
91
+ meta = FomoMetaData.new(data['meta']['per_page'].to_i, data['meta']['page'].to_i, data['meta']['total_count'].to_i, data['meta']['total_pages'].to_i)
92
+ FomoEventsWithMeta.new(list, meta)
93
+ rescue JSON::ParserError => _
94
+ # String was not valid
95
+ end
96
+ end
97
+
67
98
  # Create event
68
99
  #
69
100
  # Arguments:
@@ -143,27 +174,28 @@ class Fomo
143
174
  http = Net::HTTP.new(uri.host, uri.port)
144
175
  http.use_ssl = true
145
176
  headers = {
146
- 'Authorization' => 'Token ' + @auth_token
177
+ 'Authorization' => 'Token ' + @auth_token,
178
+ 'User-Agent' => 'Fomo/Ruby/' + @version
147
179
  }
148
180
  case method
149
181
  when 'GET'
150
- request = Net::HTTP::Get.new(uri.path, initheader=headers)
182
+ request = Net::HTTP::Get.new(api_path, initheader=headers)
151
183
  response = http.request(request)
152
184
  return response.body
153
185
  when 'POST'
154
186
  headers['Content-Type'] = 'application/json'
155
- request = Net::HTTP::Post.new(uri.path, initheader=headers)
187
+ request = Net::HTTP::Post.new(api_path, initheader=headers)
156
188
  request.body = data.to_json
157
189
  response = http.request(request)
158
190
  return response.body
159
191
  when 'PATCH'
160
192
  headers['Content-Type'] = 'application/json'
161
- request = Net::HTTP::Patch.new(uri.path, initheader=headers)
193
+ request = Net::HTTP::Patch.new(api_path, initheader=headers)
162
194
  request.body = data.to_json
163
195
  response = http.request(request)
164
196
  return response.body
165
197
  when 'DELETE'
166
- request = Net::HTTP::Delete.new(uri.path, initheader=headers)
198
+ request = Net::HTTP::Delete.new(api_path, initheader=headers)
167
199
  response = http.request(request)
168
200
  return response.body
169
201
  else
@@ -0,0 +1,32 @@
1
+ # Copyright (c) 2016. Fomo. https://www.usefomo.com
2
+ #
3
+ # Author:: Fomo (mailto:hello@usefomo.com)
4
+ # Copyright:: Copyright (c) 2016. Fomo. https://www.usefomo.com
5
+ # License:: MIT
6
+
7
+ require 'json'
8
+
9
+ # This class holds attributes of event, object returned by API
10
+ class FomoEventsWithMeta
11
+
12
+ # List of events
13
+ attr_accessor :events
14
+
15
+ # Meta data
16
+ attr_accessor :meta
17
+
18
+ # Initializes FomoMetaData object
19
+ def initialize(events=[], meta=nil)
20
+ @events = events
21
+ @meta = meta
22
+ end
23
+
24
+ # Return JSON serialized object
25
+ def to_json
26
+ hash = {}
27
+ self.instance_variables.each do |var|
28
+ hash[var.to_s.sub(/^@/, '')] = self.instance_variable_get var
29
+ end
30
+ '{"event":' + hash.to_json + '}'
31
+ end
32
+ end
@@ -0,0 +1,40 @@
1
+ # Copyright (c) 2016. Fomo. https://www.usefomo.com
2
+ #
3
+ # Author:: Fomo (mailto:hello@usefomo.com)
4
+ # Copyright:: Copyright (c) 2016. Fomo. https://www.usefomo.com
5
+ # License:: MIT
6
+
7
+ require 'json'
8
+
9
+ # This class holds attributes of event, object returned by API
10
+ class FomoMetaData
11
+
12
+ # Page size
13
+ attr_accessor :per_page
14
+
15
+ # Page number
16
+ attr_accessor :page
17
+
18
+ # Total count
19
+ attr_accessor :total_count
20
+
21
+ # Total pages
22
+ attr_accessor :total_pages
23
+
24
+ # Initializes FomoMetaData object
25
+ def initialize(per_page=30, page=1, total_count=0, total_pages=1)
26
+ @per_page = per_page
27
+ @page = page
28
+ @total_count = total_count
29
+ @total_pages = total_pages
30
+ end
31
+
32
+ # Return JSON serialized object
33
+ def to_json
34
+ hash = {}
35
+ self.instance_variables.each do |var|
36
+ hash[var.to_s.sub(/^@/, '')] = self.instance_variable_get var
37
+ end
38
+ '{"event":' + hash.to_json + '}'
39
+ end
40
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fomo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fomo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-02 00:00:00.000000000 Z
11
+ date: 2016-09-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Fomo Ruby SDK is the official SDK wrapper for the Fomo API service
14
14
  email:
@@ -21,6 +21,8 @@ files:
21
21
  - lib/fomo_delete_message_response.rb
22
22
  - lib/fomo_event.rb
23
23
  - lib/fomo_event_basic.rb
24
+ - lib/fomo_events_with_meta.rb
25
+ - lib/fomo_meta_data.rb
24
26
  homepage: https://github.com/usefomo/fomo-ruby-sdk
25
27
  licenses:
26
28
  - MIT
@@ -31,17 +33,17 @@ require_paths:
31
33
  - lib
32
34
  required_ruby_version: !ruby/object:Gem::Requirement
33
35
  requirements:
34
- - - ! '>='
36
+ - - ">="
35
37
  - !ruby/object:Gem::Version
36
38
  version: '1.9'
37
39
  required_rubygems_version: !ruby/object:Gem::Requirement
38
40
  requirements:
39
- - - ! '>='
41
+ - - ">="
40
42
  - !ruby/object:Gem::Version
41
43
  version: '0'
42
44
  requirements: []
43
45
  rubyforge_project:
44
- rubygems_version: 2.4.8
46
+ rubygems_version: 2.6.6
45
47
  signing_key:
46
48
  specification_version: 4
47
49
  summary: Fomo