yammer4r 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'spec/rake/spectask'
6
+ require 'yammer4r'
7
+
8
+ desc "Run all specs"
9
+ Spec::Rake::SpecTask.new('spec') do |t|
10
+ t.spec_files = FileList['spec/**/*spec.rb']
11
+ end
12
+
13
+ task :default => [:spec]
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ Test! There are currently no tests for yammer4r, and that makes me very sad.
2
+ Switch to HTTParty instead of yammer_request.
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Instructions:
4
+ #
5
+ # Register your application at https://www.yammer.com/client_applications/new
6
+ # Upon successful registration, you'll recieve your consumer key and secret.
7
+ # Pass these values on the command line as --key (-k) and --secret (-s) then
8
+ # follow the instructions.
9
+
10
+ require 'optparse'
11
+ require 'rubygems'
12
+ require 'oauth'
13
+
14
+ OPTIONS = {
15
+ :outfile => 'oauth.yml'
16
+ }
17
+
18
+ YAMMER_OAUTH = "https://www.yammer.com"
19
+
20
+ ARGV.options do |o|
21
+ script_name = File.basename($0)
22
+
23
+ o.set_summary_indent(' ')
24
+ o.banner = "Usage: #{script_name} [OPTIONS]"
25
+ o.define_head "Create a yaml file for yammer oauth"
26
+ o.separator ""
27
+ o.separator "[-k] and [-s] options are mandatory"
28
+ o.separator ""
29
+
30
+ o.on("-o", "--outfile=[val]", String,
31
+ "Yaml output file",
32
+ "Default: #{OPTIONS[:outfile]}") { |OPTIONS[:outfile]| }
33
+ o.on("-k", "--key=val", String,
34
+ "Consumer key for Yammer app") { |key| OPTIONS[:key] = key}
35
+ o.on("-s", "--secret=val", String,
36
+ "Consumer secret for Yammer app") { |secret| OPTIONS[:secret] = secret}
37
+
38
+ o.separator ""
39
+
40
+ o.on_tail("-h", "--help", "Show this help message.") { puts o; exit }
41
+ o.parse!
42
+ end
43
+
44
+ unless OPTIONS[:key] && OPTIONS[:secret]
45
+ raise ArgumentError, "Must supply consumer key and secret (use -h for help)"
46
+ end
47
+
48
+ consumer = OAuth::Consumer.new OPTIONS[:key], OPTIONS[:secret], {:site => YAMMER_OAUTH}
49
+ request_token = consumer.get_request_token
50
+
51
+ puts "Please visit the following URL in your browser to authorize your application, then enter the 4 character security code when done: #{request_token.authorize_url}"
52
+ oauth_verifier = gets
53
+ response = consumer.token_request(consumer.http_method,
54
+ (consumer.access_token_url? ? consumer.access_token_url : consumer.access_token_path),
55
+ request_token,
56
+ {},
57
+ :oauth_verifier => oauth_verifier.chomp)
58
+ access_token = OAuth::AccessToken.new(consumer,response[:oauth_token],response[:oauth_token_secret])
59
+
60
+ oauth_yml = <<-EOT
61
+ consumer:
62
+ key: #{OPTIONS[:key]}
63
+ secret: #{OPTIONS[:secret]}
64
+ access:
65
+ token: #{access_token.token}
66
+ secret: #{access_token.secret}
67
+ EOT
68
+
69
+ File.open(OPTIONS[:outfile], "w") do |f|
70
+ f.write oauth_yml
71
+ end
@@ -13,6 +13,7 @@ module Yammer
13
13
  end
14
14
 
15
15
  consumer = OAuth::Consumer.new(options[:consumer][:key], options[:consumer][:secret], :site => yammer_url)
16
+ consumer.http.set_debug_output($stderr) if options[:verbose] == true
16
17
  @access_token = OAuth::AccessToken.new(consumer, options[:access][:token], options[:access][:secret])
17
18
  end
18
19
 
@@ -28,7 +29,7 @@ module Yammer
28
29
  ml = parsed_response['messages'].map do |m|
29
30
  mash(m)
30
31
  end
31
- Yammer::MessageList.new(ml, older_available, self)
32
+ Yammer::MessageList.new(ml, older_available, self)
32
33
  end
33
34
 
34
35
  # POST or DELETE a message
@@ -37,10 +38,9 @@ module Yammer
37
38
  yammer_request(action, params)
38
39
  end
39
40
 
40
- def users
41
- JSON.parse(yammer_request(:get, {:resource => :users}).body).map do |u|
42
- Yammer::User.new(mash(u), self)
43
- end
41
+ def users(params = {})
42
+ params.merge!(:resource => :users)
43
+ JSON.parse(yammer_request(:get, params).body).map { |u| Yammer::User.new(mash(u), self) }
44
44
  end
45
45
 
46
46
  def user(id)
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
2
+ require 'yammer4r'
3
+ require 'spec'
@@ -0,0 +1,53 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'ostruct'
3
+
4
+ describe Yammer::Client do
5
+
6
+ context "creating" do
7
+
8
+ before(:each) do
9
+ mock_consumer = mock(OAuth::Consumer)
10
+ OAuth::Consumer.stub!("new").and_return(mock_consumer)
11
+ @mock_http = mock("http")
12
+ mock_consumer.stub!("http").and_return(@mock_http)
13
+ end
14
+
15
+ it "can be configured to be verbose" do
16
+ @mock_http.should_receive("set_debug_output").with($stderr)
17
+ Yammer::Client.new(:consumer => {}, :access => {}, :verbose => true)
18
+ end
19
+
20
+ it "should not be configured to be verbose unless asked to be" do
21
+ @mock_http.should_not_receive("set_debug_output")
22
+ Yammer::Client.new(:consumer => {}, :access => {})
23
+ end
24
+
25
+ it "should not be configured to be verbose if asked not to be" do
26
+ @mock_http.should_not_receive("set_debug_output")
27
+ Yammer::Client.new(:consumer => {}, :access => {}, :verbose => false)
28
+ end
29
+
30
+ end
31
+
32
+ context "users" do
33
+
34
+ before(:each) do
35
+ @mock_access_token = mock(OAuth::AccessToken)
36
+ @response = OpenStruct.new(:code => 200, :body => '{}')
37
+ OAuth::AccessToken.stub!("new").and_return(@mock_access_token)
38
+ @client = Yammer::Client.new(:consumer => {}, :access => {})
39
+ end
40
+
41
+ it "should request the first page by default" do
42
+ @mock_access_token.should_receive("get").with("/api/v1/users.json").and_return(@response)
43
+ @client.users
44
+ end
45
+
46
+ it "can request a specified page" do
47
+ @mock_access_token.should_receive("get").with("/api/v1/users.json?page=2").and_return(@response)
48
+ @client.users(:page => 2)
49
+ end
50
+
51
+ end
52
+
53
+ end
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yammer4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Patterson
8
8
  - Jason Stewart
9
+ - Peter Moran
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
13
 
13
- date: 2009-08-12 00:00:00 -04:00
14
+ date: 2009-12-29 00:00:00 -05:00
14
15
  default_executable:
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
@@ -44,7 +45,7 @@ dependencies:
44
45
  version: 0.3.5
45
46
  version:
46
47
  description: Yammer4R provides an object based API to query or update your Yammer account via pure Ruby. It hides the ugly HTTP/REST code from your code.
47
- email: jimp79@gmail.com
48
+ email: workingpeter@gmail.com
48
49
  executables: []
49
50
 
50
51
  extensions: []
@@ -55,14 +56,19 @@ files:
55
56
  - README
56
57
  - example.rb
57
58
  - oauth.yml.template
59
+ - Rakefile
60
+ - TODO
61
+ - bin/yammer_create_oauth_yml.rb
58
62
  - lib/yammer4r.rb
59
63
  - lib/yammer/client.rb
60
64
  - lib/yammer/message.rb
61
65
  - lib/yammer/message_list.rb
62
66
  - lib/yammer/user.rb
63
67
  - lib/ext/core_ext.rb
68
+ - spec/spec_helper.rb
69
+ - spec/yammer/client_spec.rb
64
70
  has_rdoc: true
65
- homepage: http://github.com/jpatterson/yammer4r
71
+ homepage: http://github.com/pmoran/yammer4r
66
72
  licenses: []
67
73
 
68
74
  post_install_message: