exist 0.1.0.beta.3 → 0.1.0.beta.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0986bf7fc3179f7b6454e934da0ddb6130fe7b7
4
- data.tar.gz: 67587540565de5faa21f3b2b8f9fad67f966d5bd
3
+ metadata.gz: 21dab1306f76bac038b16bfc2d7c6e5ccb43ea23
4
+ data.tar.gz: 5217e66cc73f48eceb15e6baa470f9304c41fa5a
5
5
  SHA512:
6
- metadata.gz: 8132cb4aabb07dc2a42673e0733351fb8366e11fe345f05630c1aed154105b700d57ac28cfc0c4a6adf651df6c375cf5ae256f8c7d95097b926ef184b2ab2fdf
7
- data.tar.gz: f94ada28b20e7cec9d065bc54cc7d0020df0db38bdef701ba17c57e016a8bce142481df8f363fe1444e72513869b867597ecc7f9543729a4294c899d32e886b6
6
+ metadata.gz: 306e8f7e13843f67f036ace37e9329fbb113a43593e9a0cee432e58b5bf44eb1da7c4827d8710ab03dc3d9d17aa7127e4fa5faf8121d6d906d85fe06bc3ee534
7
+ data.tar.gz: c2ccf39403583e638823aaa0a803a60dc3ed9cada21bfa77afe902ec11b634a837670d6e02ff2682608ec8907d9dae4e95f3e3989f583d84103b2512771c4c7e
@@ -21,7 +21,7 @@ module Exist
21
21
  end
22
22
 
23
23
  def me
24
- User.new(client.get('users/$self/').body)
24
+ User.new(user_resource(nil))
25
25
  end
26
26
 
27
27
  def overview(username = '$self')
@@ -29,65 +29,57 @@ module Exist
29
29
  end
30
30
 
31
31
  def attributes(limit: 31)
32
- response = client.get('users/$self/attributes/', limit: limit).body
33
-
32
+ response = user_resource('attributes', limit: limit)
34
33
  AttributeList.new(attributes: response)
35
34
  end
36
35
 
37
36
  # Date format is YYYY-mm-dd
38
37
  def attribute(attribute, limit: 31, page: 1, oldest_date: nil, newest_date: nil)
39
- response = client.get(
40
- "users/$self/attributes/#{attribute}/",
41
- page: page, limit: limit, date_min: oldest_date, date_max: newest_date
42
- ).body
38
+ response = paginated_user_resource(
39
+ "attributes/#{attribute}", page, limit, oldest_date, newest_date
40
+ )
43
41
  AttributeList.new(
44
- attributes: response['results'],
45
- total: response['count'],
42
+ attributes: response['results'], total: response['count']
46
43
  )
47
44
  end
48
45
 
49
46
  def insights(limit: 31, page: 1, oldest_date: nil, newest_date: nil)
50
- response = client.get(
51
- "users/$self/insights/",
52
- page: page, limit: limit, date_min: oldest_date, date_max: newest_date
47
+ response = paginated_user_resource(
48
+ 'insights', page, limit, oldest_date, newest_date
53
49
  )
54
50
 
55
- InsightList.new(
56
- insights: response.body['results'],
57
- total: response.body['count'],
58
- )
51
+ InsightList.new(insights: response['results'], total: response['count'])
59
52
  end
60
53
 
61
54
  def insights_for_attribute(attribute, limit: 31, page: 1, oldest_date: nil, newest_date: nil)
62
- response = client.get(
63
- "users/$self/insights/attribute/#{attribute}/",
64
- page: page, limit: limit, date_min: oldest_date, date_max: newest_date
55
+ response = paginated_user_resource(
56
+ "insights/attribute/#{attribute}",
57
+ page, limit, oldest_date, newest_date
65
58
  )
66
59
  InsightList.new(
67
- insights: response.body['results'],
68
- total: response.body['count'],
60
+ insights: response['results'],
61
+ total: response['count'],
69
62
  )
70
63
  end
71
64
 
72
65
  def averages
73
- response = client.get('users/$self/averages/')
74
- AverageList.new(averages: response.body)
66
+ response = user_resource('averages')
67
+ AverageList.new(averages: response)
75
68
  end
76
69
 
77
70
  def average_for_attribute(attribute, limit: 31, page: 1, oldest_date: nil, newest_date: nil)
78
- response = client.get(
79
- "users/$self/averages/attribute/#{attribute}/",
80
- page: page, limit: limit, date_min: oldest_date, date_max: newest_date
81
- ).body
71
+ response = paginated_user_resource(
72
+ "averages/attribute/#{attribute}", page, limit, oldest_date, newest_date
73
+ )
82
74
 
83
75
  AverageList.new(averages: response['results'], total: response['count'])
84
76
  end
85
77
 
86
- def correlations(username, attribute,
87
- limit: 31, page: 1, oldest_date: nil, newest_date: nil,
88
- latest_only: false)
78
+ def correlations(username, attribute, limit: 31, page: 1, oldest_date: nil,
79
+ newest_date: nil, latest_only: false)
89
80
 
90
81
  params = { page: page, limit: limit }
82
+
91
83
  if !latest_only
92
84
  params.merge!(date_min: oldest_date, date_max: newest_date)
93
85
  else
@@ -115,6 +107,20 @@ module Exist
115
107
  end
116
108
  end
117
109
 
110
+ def user_resource(resource, params = {})
111
+ url = base_url + "users/$self/#{resource}"
112
+ url += "/" unless url.end_with?('/')
113
+
114
+ client.get(url, params).body
115
+ end
116
+
117
+ def paginated_user_resource(resource, page, limit, newest_date, oldest_date)
118
+ user_resource(resource, {
119
+ page: page, limit: limit, date_min: oldest_date,
120
+ date_max: newest_date
121
+ })
122
+ end
123
+
118
124
  def base_url
119
125
  'https://exist.io/api/1/'
120
126
  end
@@ -1,3 +1,3 @@
1
1
  module Exist
2
- VERSION = "0.1.0.beta.3"
2
+ VERSION = "0.1.0.beta.4"
3
3
  end
@@ -28,15 +28,6 @@ RSpec.configure do |config|
28
28
  config.order = :random
29
29
 
30
30
  Kernel.srand config.seed
31
-
32
- config.expect_with :rspec do |expectations|
33
- expectations.syntax = :expect
34
- end
35
-
36
- config.mock_with :rspec do |mocks|
37
- mocks.syntax = :expect
38
- mocks.verify_partial_doubles = true
39
- end
40
31
  end
41
32
 
42
33
  require 'exist'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta.3
4
+ version: 0.1.0.beta.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Perez