doattend 0.0.4 → 0.1.0

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: 55e9a582e16a82877230f4b1874de7489c78aaf2
4
- data.tar.gz: b86cec3f63f10bef4a6c11fbe4cbbfbd395a1570
3
+ metadata.gz: b430ff4f45048ed5826060285b2558271d07d9f6
4
+ data.tar.gz: 6162cf7b437b8037da812bff7b464efbb5fc96f8
5
5
  SHA512:
6
- metadata.gz: f2974578151d87e72821dd19ac4033ed886347eacad7ddfdee69985bd6f6dc1cbedfa8a704e350b2abf1634bdf9e959c88e8074a2e4665ab8f017a63817dd6f7
7
- data.tar.gz: 563148a29c6a90d79618696a53e177c3de57bac008c0d2de90333eb4055e79c27f4d14d1ffa29d775233a5a855cf2a0371b91c7a260308b4fe84acfc904bd6e3
6
+ metadata.gz: 9c6c0b675729091b1ca9453f940776eafb6fb95238050d6c33c6c1d095ec3a0cde6590028be48cf463927bd0107315b0f294622995db8c837fd08a107ddaa77f
7
+ data.tar.gz: fe830af5b2b57cce2eb87a8be8262894afd27507c83f517547f53e0b116011bb056313c3233e1cdf550d9fc0bace62052cf0dda87d523c85246dac9a606297fe
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # DoAttend
2
2
 
3
- Rails generator and functions to communicate the DoAttend API.
3
+ [![Gem Version](https://badge.fury.io/rb/doattend.png)](http://badge.fury.io/rb/doattend)
4
+ [![Code Climate](https://codeclimate.com/github/swaroopsm/doattend.png)](https://codeclimate.com/github/swaroopsm/doattend)
5
+
6
+ Rails generator and functions to communicate the DoAttend API. You need to have a DoAttend API key to communicate the DoAttend API. If you do not have one yet, you can contact DoAttend to get an API key.
4
7
 
5
8
  ## Installation
6
9
 
@@ -18,7 +21,37 @@ Or install it yourself as:
18
21
 
19
22
  ## Usage
20
23
 
21
- TODO: Write usage instructions here
24
+ Doattend provides a rails generator that gets you started quikly.
25
+ Run the following generator to generate config/doattend.yml
26
+
27
+ $ rails g doattend:install -e YOUR_DOATTEND_EVENT_ID -k YOUR_DOATTEND_API_KEY
28
+
29
+ If you are not using Rails you can use require to include it:
30
+ $ require "doattend"
31
+
32
+ ## Getting Started
33
+ Rails Way:
34
+ @doattend = Doattend::Base.new # This loads the key and event that was generated from config/doattend.yml
35
+
36
+ Non-Rails Way:
37
+ @doattend = Doattend::Base.new('YOUR_DOATTEND_EVENT_ID', 'YOUR_DOATTEND_API_KEY')
38
+
39
+
40
+ ## Methods
41
+ #### Fetch all data from DoAttend
42
+ @doattend.fetch
43
+
44
+ #### Get total tickets
45
+ @doattend.aggregate
46
+
47
+ #### Get ticket names/types used in an event
48
+ @doattend.ticket.names
49
+
50
+ #### Get total number of registrations for a ticket name/type
51
+ @doattend.ticket.aggregate('ticket_type')
52
+
53
+ Eg.:
54
+ @doattend.ticket.aggregate(@doattend.ticket.names.first)
22
55
 
23
56
  ## Contributing
24
57
 
@@ -1,11 +1,3 @@
1
1
  require "doattend/version"
2
2
  require "doattend/base.rb"
3
3
 
4
- module Doattend
5
-
6
- # Fetch data from DoAttend API.
7
- def self.fetch
8
- Doattend::Base.fetch
9
- end
10
-
11
- end
@@ -1,19 +1,46 @@
1
1
  require "rest-client"
2
+ require "json"
3
+
4
+ require_relative "ticket.rb"
2
5
 
3
6
  module Doattend
4
7
 
5
8
  class Base
6
9
 
7
- def self.fetch
8
- conf = YAML.load_file("#{Rails.root}/config/doattend.yml")
9
- url = "http://doattend.com/api/events/#{conf['doattend']['event']}/participants_list.json?api_key=#{conf['doattend']['key']}"
10
+ attr_accessor :event, :key, :result
11
+
12
+ def initialize(e=nil, k=nil)
13
+ if defined? Rails
14
+ conf = YAML.load_file("#{Rails.root}/config/doattend.yml")
15
+ self.event = conf['doattend']['event']
16
+ self.key = conf['doattend']['key']
17
+ else
18
+ self.event = e
19
+ self.key = k
20
+ end
21
+
22
+ end
23
+
24
+ # Request DoAttend and fetch results.
25
+ def fetch
26
+ url = "http://doattend.com/api/events/#{self.event}/participants_list.json?api_key=#{self.key}"
10
27
  begin
11
- RestClient.get(url)
28
+ self.result = JSON.parse(RestClient.get(url))
12
29
  rescue Exception => e
13
30
  e
14
31
  end
15
32
  end
16
33
 
34
+ # Get Total Participants.
35
+ def aggregate
36
+ self.result['participants'].size
37
+ end
38
+
39
+ # Use methods of Ticket class.
40
+ def ticket
41
+ Doattend::Ticket.new(self.result['participants'])
42
+ end
43
+
17
44
  end
18
45
 
19
46
  end
@@ -0,0 +1,23 @@
1
+ module Doattend
2
+
3
+ class Ticket
4
+
5
+ attr_accessor :result
6
+
7
+ def initialize(result)
8
+ self.result = result
9
+ end
10
+
11
+ # Returns different ticket names that is available for the event.
12
+ def names
13
+ self.result.map{ |t| t['Ticket_Name'] }.uniq
14
+ end
15
+
16
+ # Returns number of registrations for a ticket type
17
+ def aggregate(name)
18
+ self.result.count{ |t| t['Ticket_Name'] == name }
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Doattend
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doattend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Swaroop SM
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: yaml
70
+ name: json
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - '>='
@@ -90,6 +90,7 @@ files:
90
90
  - README.md
91
91
  - Gemfile
92
92
  - Rakefile
93
+ - lib/doattend/ticket.rb
93
94
  - lib/doattend/version.rb
94
95
  - lib/doattend/base.rb
95
96
  - lib/generators/doattend/install/USAGE