ruby-sendhub 0.0.4 → 0.0.5

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.
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # ruby-sendhub
2
2
 
3
3
  ruby-sendhub is a simple API wrapper for interacting with [SendHub API](http://www.sendhub.com/developer)
4
- It's my first ever gem, so I'm crying right now as you read this.
5
4
 
6
5
  ##Installation
7
6
 
@@ -11,7 +10,7 @@ It's my first ever gem, so I'm crying right now as you read this.
11
10
 
12
11
  A SendHub account. Get your API key [here](https://www.sendhub.com/settings)
13
12
 
14
- ##Usage
13
+ ##Getting started
15
14
 
16
15
  Create a new instance of the API wrapper:
17
16
 
@@ -25,15 +24,90 @@ SendHub API uses RESTful services. Every methods begin with post, put, update, o
25
24
 
26
25
  sh.post_contacts({:name => "SoonKhen OwYong", :number => 4040404040, :address => "1 Infinite Loop", :city => "Cupertino", :zip => "95014"})
27
26
 
28
- Every put or delete requests must have :id in it
27
+ Every put or delete requests must have an :id hash key
29
28
 
30
29
  sh.delete_contacts({:id => [11]})
31
30
 
32
- ##Special Thanks
31
+ ##Messages
33
32
 
34
- * My mom and dad, seriously, first gem you know
35
- * [Amro Mousa](https://github.com/amro) for his source code on Gibbon which inspired this code
33
+ Sending a Message
36
34
 
37
- ##License
35
+ sh.post_messages({:contacts => [1111], :text => "Testing"})
38
36
 
39
- No time for this, just do whatever you want
37
+ Scheduling a Message
38
+
39
+ sh.post_messages({:contacts => [1111], :text => "Testing", :scheduled_at => "2011-02-17T20:29:40-0800"})
40
+
41
+ Get Message Status
42
+
43
+ sh.get_messages({:id => 11})
44
+
45
+ Mark Message as Read
46
+
47
+ sh.put_messages({:id => 11, :unread => "false"})
48
+
49
+ ##Contacts
50
+
51
+ Adding a Contact
52
+
53
+ sh.post_contacts({:name => "John Doe", :number => "6501234567"})
54
+
55
+ Adding a Contact with Additional Data
56
+
57
+ sh.post_contacts({:name => "John Doe", :number => "6501234567", :groups => [11,12], :address => "1 Infinite Loop", :city => "Cupertino", :zip => "95014"})
58
+
59
+ Collecting Contacts Data
60
+
61
+ sh.get_contacts
62
+
63
+ Editing a Contact
64
+
65
+ sh.put_contacts({:id => 22413, :name => "Jesse Doe", :number => 6501234567})
66
+
67
+ Deleting a Contact
68
+
69
+ sh.delete_contacts({:id => 22413})
70
+
71
+ ##Groups
72
+
73
+ Adding a Group
74
+
75
+ sh.post_groups({:name => "Regulars", :slug => "regulars", :text_to_subscribe => true})
76
+
77
+ Collect Groups List
78
+
79
+ sh.get_groups
80
+
81
+ Collect a Single Group's Contacts
82
+
83
+ sh.get_groups_contacts({:id => 1220})
84
+
85
+ Adding and Removing Contacts
86
+
87
+ sh.post_groups_contacts({:id => 1220, :add => [22081], :remove => [22411, 22412]})
88
+
89
+ Editing a Group
90
+
91
+ sh.put_groups({:id => 1220, :name => "Best Customers", :slug => "regulars", :text_to_subscribe => true})
92
+
93
+ Deleting a Group
94
+
95
+ sh.delete_groups({:id => 1220})
96
+
97
+ ##Inbox
98
+
99
+ Collecting the Inbox
100
+
101
+ sh.get_inbox
102
+
103
+ ##Threads
104
+
105
+ Viewing Threads
106
+
107
+ sh.get_threads({:id => 12555})
108
+
109
+ ##Profile
110
+
111
+ Collecting the Profile
112
+
113
+ sh.get_profile
@@ -17,16 +17,39 @@ class SendHub
17
17
  def method_missing(method, hsh = {})
18
18
  meth = method.to_s.split("_")
19
19
  if meth.first == "put" || meth.first == "delete"
20
+ if meth.last == "messages"
21
+ api_url = base_url + meth.last + "/" + hsh[:id].to_s + credentials
22
+ hsh.delete(:id)
23
+ else
24
+ api_url = base_url + meth.last + "/" + hsh[:id].to_s + credentials
25
+ end
26
+ elsif meth.first == "get" && (meth.last == "threads" || meth.last == "messages" || !hsh[:id].nil?)
20
27
  api_url = base_url + meth.last + "/" + hsh[:id].to_s + credentials
21
28
  else
22
29
  api_url = base_url + meth.last + credentials
23
30
  end
24
- ret = self.class.send(meth.first, api_url, :body => hsh.to_json).parsed_response
31
+ ret = send_request(meth.first, api_url, :body => hsh.to_json)
25
32
  ret.nil? && meth.first == "delete" ? "Aaaand it's gone" : ret
26
33
  end
27
34
 
35
+ def get_groups_contacts(hsh = {})
36
+ send_request("get", group_contacts_url(hsh), :body => hsh.to_json)
37
+ end
38
+
39
+ def post_groups_contacts(hsh = {})
40
+ send_request("post", group_contacts_url(hsh), :body => hsh.to_json)
41
+ end
42
+
28
43
  private
29
44
 
45
+ def group_contacts_url(hsh)
46
+ base_url + "groups/" + hsh[:id].to_s + "/contacts" + credentials
47
+ end
48
+
49
+ def send_request(request_type, url, json)
50
+ self.class.send(request_type, url, json).parsed_response
51
+ end
52
+
30
53
  def base_url
31
54
  "https://api.sendhub.com/v1/"
32
55
  end
@@ -1,5 +1,5 @@
1
1
  module Ruby
2
2
  module Sendhub
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-sendhub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-08 00:00:00.000000000 Z
12
+ date: 2012-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &19992840 !ruby/object:Gem::Requirement
16
+ requirement: &21865320 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *19992840
24
+ version_requirements: *21865320
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &19989000 !ruby/object:Gem::Requirement
27
+ requirement: &21881660 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *19989000
35
+ version_requirements: *21881660
36
36
  description: My first gem and no tests yet. Ruby wrapper for SendHub API
37
37
  email:
38
38
  - dude@owyong.sk