qualaroo 0.0.2 → 0.0.3

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: 0786649bc54770340d593a21dba5213b8dbef351
4
- data.tar.gz: 6063f24b5f99f7e26f015b2bbdfa84827582b137
3
+ metadata.gz: fec45505202df68cc727759c7a89a3493c0fd417
4
+ data.tar.gz: ef911e68228d71799f82278bed36127d50f0b964
5
5
  SHA512:
6
- metadata.gz: 6de4cb9df94fb34ee2b8aecc930672b37c0988631778697f64229a61bee404c86303b6f73c59d7accb1b0f0e0e4dc8cb67830f913d8944172b1090fc1111d355
7
- data.tar.gz: 0224559f4ffc0e52827416194acc90fed7f2480b4bf950e9e6dd2d71fe32ab08eae7a7c8f85295923c372a235fac666c43f6fe9d82ce2c50a014b32ab27c4fef
6
+ metadata.gz: caaea8eda77c32f9b2266a4d5f33c89c03f2669b4229b115185a712e203cfb15765072652dadb2bb49cdf957e5b349c41449447aee35f123c80041ac26e9dbaa
7
+ data.tar.gz: eff1587501f87266ad0d36ca96a37ec73ca9ceda874bf7d5ef5c9837a12babd0c13164689362773de8f18ba18378d10f2a98075a9e7c13f496164a6ea0b936a8
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Qualaroo
2
2
 
3
- TODO: Write a gem description
3
+ A ruby library to connect to Qualaroo's API. For more information on
4
+ their API, check out the documentation here: http://help.qualaroo.com/hc/en-us/sections/200469946-API-Documentation
4
5
 
5
6
  ## Installation
6
7
 
@@ -20,7 +21,85 @@ Or install it yourself as:
20
21
 
21
22
  ## Usage
22
23
 
23
- TODO: Write usage instructions here
24
+ First, you'll need your API key which you can find here: https://app.qualaroo.com/account
25
+
26
+ ### Set up your API keys
27
+
28
+ You can create an instance of the API client:
29
+
30
+ qualaroo = Qualaroo::Client.new("your_api_key", "your_api_secret")
31
+
32
+ Alternatively, you can set this globally and use this in an initializer
33
+ in Rails like `config/initializers/qualaroo.rb`:
34
+
35
+ Qualaroo::Client.api_key = "your_api_key"
36
+ Qualaroo::Client.api_secret = "your_api_secret"
37
+
38
+ You can also set the environment variables `QUALAROO_API_KEY` and
39
+ `QUALAROO_API_SECRET` in your `application.yml` and Qualaroo will
40
+ automatically detect this. That means, you can set up API access by just
41
+ specifying:
42
+
43
+ qualaroo = Qualaroo::Client.new
44
+
45
+ ### Responses
46
+
47
+ Once you've set your API keys, you can access responses to nudges:
48
+
49
+ qualaroo = Qualaroo::Client.new
50
+ qualaroo.responses("your_nudge_id")
51
+
52
+ # or if you set the keys globally
53
+
54
+ Qualaroo::Client.responses("your_nudge_id")
55
+
56
+ This returns the first 500 responses as a Ruby hash.
57
+
58
+ Their API also accepts various options:
59
+
60
+ # Date Ranges
61
+ You can request records for a particular date range. To do this, add start_date and/or end_date parameters to the URL. The value of these parameters must be a integer representing "UNIX time" in seconds. For example, the date/time "2013-07-15 17:47:24 -0700" must be represented as 1373935644.
62
+
63
+ # Pagination
64
+ offset -- a non-negative integer. For example, offset=1000 means that the API will return records that match your query starting with response number 1001. If offset is not provided, the API will start from the beginning, response number 1.
65
+ limit -- the number of records you want to get in one response. The number must be between 0 and 500. If limit is not provided, the API will retrieve up to 500 responses.
66
+
67
+ You must pass in an integer version of a time to `start_date` or
68
+ `end_date` for it to be handled properly:
69
+
70
+ qualaroo = Qualaroo::Client.new
71
+ qualaroo.responses("your_nudge_id", {
72
+ start_date: Time.zone.yesterday.to_i,
73
+ end_date: Time.zone.now.to_i,
74
+ offset: 500,
75
+ limit: 30
76
+ })
77
+
78
+ # or if you set the keys globally
79
+
80
+ Qualaroo::Client.responses("your_nudge_id", {
81
+ start_date: Time.zone.yesterday.to_i,
82
+ end_date: Time.zone.now.to_i,
83
+ offset: 500,
84
+ limit: 30
85
+ })
86
+
87
+ ### All Responses For A Nudge
88
+
89
+ If you want to access all the responses from a Nudge without dealing
90
+ with pagination, you can use the `all_responses` method to do this. It
91
+ will make a series of API requests and collect the results and return
92
+ them to you all together.
93
+
94
+ qualaroo = Qualaroo::Client.new
95
+ qualaroo.all_responses("your_nudge_id)
96
+
97
+ # or if you set the keys globally
98
+
99
+ Qualaroo::Client.all_responses("your_nudge_id")
100
+
101
+ You can also pass the `start_date` and `end_date` options into this
102
+ method to get all responses over a given time period.
24
103
 
25
104
  ## Contributing
26
105
 
@@ -7,13 +7,38 @@ module Qualaroo
7
7
  base_uri 'app.qualaroo.com/api/v1'
8
8
  format :json
9
9
 
10
- def initialize(key, secret)
11
- @auth = {username: key, password: secret}
10
+ attr_accessor :api_key, :api_secret
11
+
12
+ def initialize(api_key, api_secret)
13
+ @auth = {
14
+ username: api_key || self.class.api_key || ENV['QUALAROO_API_KEY'],
15
+ password: api_secret || self.class.api_secret || ENV['QUALAROO_API_SECRET']
16
+ }
17
+ end
18
+
19
+ def responses(nudge_id, query={}, options={})
20
+ options.merge!(basic_auth: @auth, query: query)
21
+ self.class.get("/nudges/#{nudge_id}/responses.json", options)
22
+ end
23
+
24
+ def all_responses(nudge_id, query={}, options={})
25
+ offset = 0
26
+ all_responses = []
27
+
28
+ while (page_responses = responses(nudge_id, query.merge(offset: offset), options)) && page_responses.any?
29
+ all_responses += page_responses
30
+ offset += 500
31
+ end
32
+
33
+ all_responses
12
34
  end
13
35
 
14
- def responses(survey_id, options={})
15
- options.merge!(basic_auth: @auth)
16
- self.class.get "/nudges/#{survey_id}/responses.json", options
36
+ class << self
37
+ attr_accessor :api_key, :api_secret
38
+
39
+ def method_missing(sym, *args, &block)
40
+ new(api_key, api_secret).send(sym, *args, &block)
41
+ end
17
42
  end
18
43
  end
19
44
  end
@@ -1,3 +1,3 @@
1
1
  module Qualaroo
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qualaroo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-18 00:00:00.000000000 Z
11
+ date: 2014-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler