Class: GlipSdk::REST::Posts
- Inherits:
-
Object
- Object
- GlipSdk::REST::Posts
- Defined in:
- lib/glip_sdk/rest/posts.rb
Instance Method Summary collapse
- #get(opts = {}) ⇒ Object
-
#initialize(rc_sdk) ⇒ Posts
constructor
A new instance of Posts.
- #observe(observer) ⇒ Object
- #post(opts = {}) ⇒ Object
Constructor Details
#initialize(rc_sdk) ⇒ Posts
4 5 6 |
# File 'lib/glip_sdk/rest/posts.rb', line 4 def initialize(rc_sdk) @api = rc_sdk end |
Instance Method Details
#get(opts = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/glip_sdk/rest/posts.rb', line 27 def get(opts = {}) if opts.key? :postId return @api.http.get "glip/posts/#{opts[:postId]}" end @api.http.get do |req| req.url "glip/posts" req.headers['Content-Type'] = 'application/json' req.body = opts end end |
#observe(observer) ⇒ Object
38 39 40 41 42 |
# File 'lib/glip_sdk/rest/posts.rb', line 38 def observe(observer) @subscription = @api.create_subscription() @subscription.subscribe(['/restapi/v1.0/account/~/extension/~/glip/posts']) @subscription.add_observer observer end |
#post(opts = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/glip_sdk/rest/posts.rb', line 8 def post(opts = {}) unless opts.key? :text raise ArgumentError, "Text must be provided to post message" end unless opts.key?(:groupId) || opts.key?(:groupName) raise ArgumentError, "Group Id or Group Name must be provided" end group_id = (opts.key?(:groupName) && !opts.key?(:groupId)) \ ? @groups.groups_name2id[opts[:groupName]] : opts[:groupId] @api.http.post do |req| req.url 'glip/posts' req.headers['Content-Type'] = 'application/json' req.body = { groupId: group_id, text: opts[:text] } end end |