Skip to content

Commit 7746623

Browse files
committed
Add syntax highlighting to the README. From: dcparker#75
1 parent 35f617f commit 7746623

1 file changed

Lines changed: 104 additions & 88 deletions

File tree

README.markdown

Lines changed: 104 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ Second, this gem is getting back on track. See [this issue here](https://github.
1616

1717
Extra thanks for specific feature contributions from:
1818

19-
* [Justin Perkins](http://github.com/justinperkins)
20-
* [Mikkel Malmberg](http://github.com/mikker)
21-
* [Julien Blanchard](http://github.com/julienXX)
22-
* [Federico Galassi](http://github.com/fgalassi)
19+
* [Justin Perkins](https://github.com/justinperkins)
20+
* [Mikkel Malmberg](https://github.com/mikker)
21+
* [Julien Blanchard](https://github.com/julienXX)
22+
* [Federico Galassi](https://github.com/fgalassi)
23+
* [Foo Bar](https://github.com/strcmp)
24+
* [Ryan Jacobs](https://github.com/ryanmjacobs)
25+
* [Gabriel Engel](https://github.com/gabrielengel)
26+
* [Steve Cockram](https://github.com/scockram)
2327

2428
## Description
2529

@@ -43,101 +47,111 @@ A Rubyesque interface to Gmail, with all the tools you'll need. Search, read and
4347

4448
### 1) Require gmail
4549

46-
require 'gmail'
47-
50+
```ruby
51+
require 'gmail'
52+
```
53+
4854
### 2) Start an authenticated gmail session
4955

50-
# If you pass a block, the session will be passed into the block,
51-
# and the session will be logged out after the block is executed.
52-
gmail = Gmail.new(username, password)
53-
# ...do things...
54-
gmail.logout
56+
```ruby
57+
# If you pass a block, the session will be passed into the block,
58+
# and the session will be logged out after the block is executed.
59+
gmail = Gmail.new(username, password)
60+
# ...do things...
61+
gmail.logout
5562

56-
Gmail.new(username, password) do |gmail|
57-
# ...do things...
58-
end
63+
Gmail.new(username, password) do |gmail|
64+
# ...do things...
65+
end
66+
```
5967

6068
### 3) Count and gather emails!
61-
62-
# Get counts for messages in the inbox
63-
gmail.inbox.count
64-
gmail.inbox.count(:unread)
65-
gmail.inbox.count(:read)
66-
67-
# Count with some criteria
68-
gmail.inbox.count(:after => Date.parse("2010-02-20"), :before => Date.parse("2010-03-20"))
69-
gmail.inbox.count(:on => Date.parse("2010-04-15"))
70-
gmail.inbox.count(:from => "myfriend@gmail.com")
71-
gmail.inbox.count(:to => "directlytome@gmail.com")
72-
73-
# Combine flags and options
74-
gmail.inbox.count(:unread, :from => "myboss@gmail.com")
75-
76-
# Labels work the same way as inbox
77-
gmail.mailbox('Urgent').count
78-
79-
# Getting messages works the same way as counting: optional flag, and optional arguments
80-
# Remember that every message in a conversation/thread will come as a separate message.
81-
gmail.inbox.emails(:unread, :before => Date.parse("2010-04-20"), :from => "myboss@gmail.com")
82-
83-
# Get messages without marking them as read on the server.
84-
gmail.peek = true
85-
gmail.inbox.emails(:unread, :before => Date.parse("2010-04-20"), :from => "myboss@gmail.com")
86-
69+
70+
```ruby
71+
# Get counts for messages in the inbox
72+
gmail.inbox.count
73+
gmail.inbox.count(:unread)
74+
gmail.inbox.count(:read)
75+
76+
# Count with some criteria
77+
gmail.inbox.count(:after => Date.parse("2010-02-20"), :before => Date.parse("2010-03-20"))
78+
gmail.inbox.count(:on => Date.parse("2010-04-15"))
79+
gmail.inbox.count(:from => "myfriend@gmail.com")
80+
gmail.inbox.count(:to => "directlytome@gmail.com")
81+
82+
# Combine flags and options
83+
gmail.inbox.count(:unread, :from => "myboss@gmail.com")
84+
85+
# Labels work the same way as inbox
86+
gmail.mailbox('Urgent').count
87+
88+
# Getting messages works the same way as counting: optional flag, and optional arguments
89+
# Remember that every message in a conversation/thread will come as a separate message.
90+
gmail.inbox.emails(:unread, :before => Date.parse("2010-04-20"), :from => "myboss@gmail.com")
91+
92+
# Get messages without marking them as read on the server.
93+
gmail.peek = true
94+
gmail.inbox.emails(:unread, :before => Date.parse("2010-04-20"), :from => "myboss@gmail.com")
95+
```
96+
8797
### 4) Work with emails!
8898

89-
# any news older than 4-20, mark as read and archive it...
90-
gmail.inbox.emails(:before => Date.parse("2010-04-20"), :from => "news@nbcnews.com").each do |email|
91-
email.mark(:read) # can also mark :unread or :spam
92-
email.archive!
93-
end
94-
95-
# delete emails from X...
96-
gmail.inbox.emails(:from => "x-fiancé@gmail.com").each do |email|
97-
email.delete!
98-
end
99-
100-
# Save all attachments in the "Faxes" label to a folder
101-
folder = "/where/ever"
102-
gmail.mailbox("Faxes").emails.each do |email|
103-
email.attachments.each do |attachment|
104-
file = File.new(folder + attachment.filename, "w+")
105-
file << attachment.decoded
106-
file.close
107-
end
108-
end
109-
110-
# Add a label to a message
111-
email.label("Faxes")
112-
113-
# Or "move" the message to a label
114-
email.move_to("Faxes")
99+
```ruby
100+
# any news older than 4-20, mark as read and archive it...
101+
gmail.inbox.emails(:before => Date.parse("2010-04-20"), :from => "news@nbcnews.com").each do |email|
102+
email.mark(:read) # can also mark :unread or :spam
103+
email.archive!
104+
end
105+
106+
# delete emails from X...
107+
gmail.inbox.emails(:from => "x-fiancé@gmail.com").each do |email|
108+
email.delete!
109+
end
110+
111+
# Save all attachments in the "Faxes" label to a folder
112+
folder = "/where/ever"
113+
gmail.mailbox("Faxes").emails.each do |email|
114+
email.attachments.each do |attachment|
115+
file = File.new(folder + attachment.filename, "w+")
116+
file << attachment.decoded
117+
file.close
118+
end
119+
end
120+
121+
# Add a label to a message
122+
email.label("Faxes")
123+
124+
# Or "move" the message to a label
125+
email.move_to("Faxes")
126+
```
115127

116128
### 5) Create new emails!
117129

118130
Creating emails now uses the amazing [Mail](http://rubygems.org/gems/mail) rubygem. See its [documentation here](http://github.com/mikel/mail). Ruby-gmail will automatically configure your Mail emails to be sent via your Gmail account's SMTP, so they will be in your Gmail's "Sent" folder. Also, no need to specify the "From" email either, because ruby-gmail will set it for you.
119131

120-
gmail.deliver do
121-
to "email@example.com"
122-
subject "Having fun in Puerto Rico!"
123-
text_part do
124-
body "Text of plaintext message."
125-
end
126-
html_part do
127-
content_type 'text/html; charset=UTF-8'
128-
body "<p>Text of <em>html</em> message.</p>"
129-
end
130-
add_file "/path/to/some_image.jpg"
131-
end
132-
# Or, generate the message first and send it later
133-
email = gmail.generate_message do
134-
to "email@example.com"
135-
subject "Having fun in Puerto Rico!"
136-
body "Spent the day on the road..."
137-
end
138-
email.deliver!
139-
# Or...
140-
gmail.deliver(email)
132+
```ruby
133+
gmail.deliver do
134+
to "email@example.com"
135+
subject "Having fun in Puerto Rico!"
136+
text_part do
137+
body "Text of plaintext message."
138+
end
139+
html_part do
140+
content_type 'text/html; charset=UTF-8'
141+
body "<p>Text of <em>html</em> message.</p>"
142+
end
143+
add_file "/path/to/some_image.jpg"
144+
end
145+
# Or, generate the message first and send it later
146+
email = gmail.generate_message do
147+
to "email@example.com"
148+
subject "Having fun in Puerto Rico!"
149+
body "Spent the day on the road..."
150+
end
151+
email.deliver!
152+
# Or...
153+
gmail.deliver(email)
154+
```
141155

142156
## Requirements
143157

@@ -149,7 +163,9 @@ Creating emails now uses the amazing [Mail](http://rubygems.org/gems/mail) rubyg
149163

150164
## Install
151165

152-
gem install ruby-gmail
166+
```ruby
167+
gem install ruby-gmail
168+
```
153169

154170
## License
155171

0 commit comments

Comments
 (0)