rb-airgram 0.0.0

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.
Files changed (2) hide show
  1. data/lib/airgram.rb +54 -0
  2. metadata +46 -0
data/lib/airgram.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'httparty'
2
+
3
+ class Airgram
4
+ class AuthenticationError < StandardError
5
+ end
6
+ include HTTParty
7
+ base_uri "https://api.airgramapp.com/1"
8
+
9
+ def initialize(auth={})
10
+ @auth = auth
11
+ end
12
+
13
+ def send_as_guest(email, msg, url=nil)
14
+ request_successful?( post("/send_as_guest", :email => email, :msg => msg, :url => url) )
15
+ end
16
+
17
+ def subscribe(email)
18
+ check_auth_details!
19
+ request_successful?( post("/subscribe", {:email => email}, @auth) )
20
+ end
21
+
22
+ def send(email, msg, url=nil)
23
+ request_successful?( post("/send", {:email => email, :msg => msg, :url => url}, @auth) )
24
+ end
25
+
26
+ def broadcast(msg, url=nil)
27
+ request_successful?( post("/broadcast", {:msg => msg, :url => url}, @auth) )
28
+ end
29
+
30
+ private
31
+
32
+ # Internal: Fire POST HTTP request.
33
+ def post(path, params = {}, auth=nil)
34
+ request(:post, path, :body => params, :basic_auth => @auth)
35
+ end
36
+
37
+ # Internal: Does the actual requests.
38
+ def request(method, path, params)
39
+ self.class.send(method, path, params)
40
+ end
41
+
42
+ def request_successful?(response)
43
+ response.parsed_response['status'] == "ok"
44
+ end
45
+
46
+ def check_auth_details!
47
+ unless @auth.has_key?(:username) && @auth.has_key?(:username)
48
+ raise AuthenticationError, "Calling a method that requires authentication with no Service Key or Service Secret!"
49
+ end
50
+ end
51
+ end
52
+
53
+ client = Airgram.new(:username => "nGv6WIINiU", :password => "dCkFoJ0o9JtffyIsi1jF")
54
+ p client.broadcast("Some msg", "http://www.bbc.com")
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rb-airgram
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jake Austwick
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-18 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: rb-airgram provides a convenient wrapper around all of the current AirGram
15
+ api methods, including those that require authentication.
16
+ email: contact@mumbodesign.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/airgram.rb
22
+ homepage: http://rubygems.org/gems/rb-airgram
23
+ licenses: []
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.10
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: Ruby Gem to interface with the AirGram service
46
+ test_files: []