adnruby 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/adnruby.rb +166 -0
  2. metadata +45 -0
data/lib/adnruby.rb ADDED
@@ -0,0 +1,166 @@
1
+ require 'net/https'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ API = "alpha-api.app.net"
6
+
7
+ module ADN
8
+ def self.token=(token)
9
+ @token = token
10
+ end
11
+
12
+ def self.token
13
+ @token
14
+ end
15
+
16
+ class User
17
+ def self.retrieve(user_id)
18
+ ADN.get("/stream/0/users/#{user_id}")
19
+ end
20
+
21
+ def self.follow(user_id)
22
+ ADN.post("/stream/0/users/#{user_id}/follow")
23
+ end
24
+
25
+ def self.unfollow(user_id)
26
+ ADN.delete("/stream/0/users/#{user_id}/follow")
27
+ end
28
+
29
+ def self.following(user_id)
30
+ ADN.get("/stream/0/users/#{user_id}/following")
31
+ end
32
+
33
+ def self.followers(user_id)
34
+ ADN.get("/stream/0/users/#{user_id}/followers")
35
+ end
36
+
37
+ def self.mute(user_id)
38
+ ADN.post("/stream/0/users/#{user_id}/mute")
39
+ end
40
+
41
+ def self.unmute(user_id)
42
+ ADN.delete("/stream/0/users/#{user_id}/mute")
43
+ end
44
+
45
+ def self.mute_list
46
+ ADN.get("/stream/0/users/me/muted")
47
+ end
48
+
49
+ # def self.posts(user_id)
50
+ # ADN::Post.by_user(user_id)
51
+ # end
52
+
53
+ # def self.mentions(user_id)
54
+ # ADN::Post.mentioning_user(user_id)
55
+ # end
56
+
57
+
58
+ end
59
+
60
+ class Post
61
+ def self.new(params)
62
+ ADN.post("/stream/0/posts", params)
63
+ end
64
+
65
+ def self.retrieve(post_id)
66
+ ADN.get("/stream/0/posts/#{post_id}")
67
+ end
68
+
69
+ def self.by_id(post_id)
70
+ self.retrieve(post_id)
71
+ end
72
+
73
+ def self.delete(post_id)
74
+ ADN.delete("/stream/0/posts/#{post_id}")
75
+ end
76
+
77
+ def self.replies(post_id, params = nil)
78
+ ADN.get("/stream/0/posts/#{post_id}/replies", params)
79
+ end
80
+
81
+ def self.by_user(user_id, params = nil)
82
+ ADN.get("/stream/0/users/#{user_id}/posts", params)
83
+ end
84
+
85
+ def self.mentioning_user(user_id, params = nil)
86
+ ADN.get("/stream/0/users/#{user_id}/mentions", params)
87
+ end
88
+
89
+ def self.stream(params = nil)
90
+ ADN.get("/stream/0/posts/stream", params)
91
+ end
92
+
93
+ def self.global_stream(params = nil)
94
+ ADN.get("/stream/0/posts/stream/global", params)
95
+ end
96
+
97
+ def self.by_hashtag(hashtag, params = nil)
98
+ ADN.get("/stream/0/posts/tag/#{hashtag}", params)
99
+ end
100
+
101
+ end
102
+
103
+ class Stream
104
+ # Not Yet Implemented
105
+ # https://github.com/appdotnet/api-spec/blob/master/resources/streams.md
106
+ end
107
+
108
+ class Subscription
109
+ # Not Yet Implemented
110
+ # https://github.com/appdotnet/api-spec/blob/master/resources/subscriptions.md
111
+ end
112
+
113
+ class Filter
114
+ # Not Yet Implemented
115
+ # https://github.com/appdotnet/api-spec/blob/master/resources/filters.md
116
+ end
117
+
118
+ class Token
119
+ def self.current
120
+ ADN.get("/stream/0/token")
121
+ end
122
+ end
123
+
124
+ def self.get(url, params = nil)
125
+ http = Net::HTTP.new(API, 443)
126
+ http.use_ssl = true
127
+
128
+ get_url = params.nil? ? url : "#{url}?#{URI.encode_www_form(params)}"
129
+ request = Net::HTTP::Get.new(get_url)
130
+ request.add_field("Authorization", "Bearer #{ADN.token}")
131
+ response = http.request(request)
132
+ return JSON.parse(response.body)
133
+ end
134
+
135
+ def self.post(url, params = nil)
136
+ http = Net::HTTP.new(API, 443)
137
+ http.use_ssl = true
138
+
139
+ request = Net::HTTP::Post.new(url)
140
+ request.set_form_data(params) if params
141
+ request.add_field("Authorization", "Bearer #{ADN.token}")
142
+ response = http.request(request)
143
+ return JSON.parse(response.body)
144
+ end
145
+
146
+ def self.put(url, params = nil)
147
+ http = Net::HTTP.new(API, 443)
148
+ http.use_ssl = true
149
+
150
+ request = Net::HTTP::Put.new(url)
151
+ request.set_form_data(params) if params
152
+ request.add_field("Authorization", "Bearer #{ADN.token}")
153
+ response = http.request(request)
154
+ return JSON.parse(response.body)
155
+ end
156
+
157
+ def self.delete(url, params = nil)
158
+ http = Net::HTTP.new(API, 443)
159
+ http.use_ssl = true
160
+
161
+ request = Net::HTTP::Delete.new(url)
162
+ request.add_field("Authorization", "Bearer #{ADN.token}")
163
+ response = http.request(request)
164
+ return JSON.parse(response.body)
165
+ end
166
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adnruby
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kishyr Ramdial
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-25 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A simple and easy to use library to interact with App.net's API
15
+ email: kishyr@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/adnruby.rb
21
+ homepage: https://github.com/kishyr/ADNRuby
22
+ licenses: []
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 1.8.6
42
+ signing_key:
43
+ specification_version: 3
44
+ summary: A Ruby library for App.net
45
+ test_files: []