Changeset 1225


Ignore:
Timestamp:
Oct 18, 2008, 2:53:43 PM (13 years ago)
Author:
nick
Message:

Rename functions in json module to be more appropriate

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides/JSON.pm

    r1224 r1225  
    125125}
    126126
    127 sub make_recentchanges_rss {
     127sub make_recentchanges_json {
    128128    my ( $self, %args ) = @_;
    129129
     
    131131}
    132132
    133 sub rss_timestamp {
    134     my ( $self, %args ) = @_;
    135 
     133sub json_timestamp {
     134    my ( $self, %args ) = @_;
     135
     136    # RSS and JSON timestamps are close, I think...
    136137    $self->json_maker->rss_timestamp(%args);
    137138}
     
    156157    my $wiki = Wiki::Toolkit->new( ... );
    157158    my $config = OpenGuides::Config->new( file => "wiki.conf" );
    158     my $rdf_writer = OpenGuides::JSON->new( wiki   => $wiki,
     159    my $json_writer = OpenGuides::JSON->new( wiki   => $wiki,
    159160                                         config => $config );
    160161
    161162    # JSON version of a node.
    162     print "Content-Type: application/rdf+xml\n\n";
    163     print $rdf_writer->emit_rdfxml( node => "Masala Zone, N1 0NU" );
     163    print "Content-Type: application/javascript\n\n";
     164    print $json_writer->emit_json( node => "Masala Zone, N1 0NU" );
    164165
    165166    # Ten most recent changes.
    166     print "Content-Type: application/rdf+xml\n";
    167     print "Last-Modified: " . $self->rss_timestamp( items => 10 ) . "\n\n";
    168     print $rdf_writer->make_recentchanges_rss( items => 10 );
     167    print "Content-Type: application/javascript\n";
     168    print "Last-Modified: " . $self->json_timestamp( items => 10 ) . "\n\n";
     169    print $json_writer->make_recentchanges_json( items => 10 );
    169170
    170171=head1 METHODS
     
    174175=item B<new>
    175176
    176     my $rdf_writer = OpenGuides::JSON->new( wiki   => $wiki,
     177    my $json_writer = OpenGuides::JSON->new( wiki   => $wiki,
    177178                                           config => $config );
    178179
     
    181182
    182183
    183 =item B<emit_rdfxml>
     184=item B<emit_json>
    184185
    185186    $wiki->write_node( "Masala Zone, N1 0NU",
     
    191192    );
    192193
    193     print "Content-Type: application/rdf+xml\n\n";
    194     print $rdf_writer->emit_rdfxml( node => "Masala Zone, N1 0NU" );
     194    print "Content-Type: application/javascript\n\n";
     195    print $json_writer->emit_json( node => "Masala Zone, N1 0NU" );
    195196
    196197B<Note:> Some of the fields emitted by the JSON generator are taken
     
    224225invoked this module with.
    225226
    226 =item B<make_recentchanges_rss>
     227=item B<make_recentchanges_json>
    227228
    228229    # Ten most recent changes.
    229     print "Content-Type: application/rdf+xml\n";
    230     print "Last-Modified: " . $rdf_writer->rss_timestamp( items => 10 ) . "\n\n";
    231     print $rdf_writer->make_recentchanges_rss( items => 10 );
     230    print "Content-Type: application/javascript\n";
     231    print "Last-Modified: " . $json_writer->json_timestamp( items => 10 ) . "\n\n";
     232    print $json_writer->make_recentchanges_json( items => 10 );
    232233
    233234    # All the changes made by bob in the past week, ignoring minor edits.
     
    239240               );
    240241
    241     print "Content-Type: application/rdf+xml\n";
    242     print "Last-Modified: " . $rdf_writer->rss_timestamp( %args ) . "\n\n";
    243     print $rdf_writer->make_recentchanges_rss( %args );
    244 
    245 =item B<rss_timestamp>
    246 
    247     print "Last-Modified: " . $rdf_writer->rss_timestamp( %args ) . "\n\n";
     242    print "Content-Type: application/javascript\n";
     243    print "Last-Modified: " . $json_writer->json_timestamp( %args ) . "\n\n";
     244    print $json_writer->make_recentchanges_json( %args );
     245
     246=item B<json_timestamp>
     247
     248    print "Last-Modified: " . $json_writer->json_timestamp( %args ) . "\n\n";
    248249
    249250Returns the timestamp of the RSS feed in POSIX::strftime style ("Tue, 29 Feb 2000
    25025112:34:56 GMT"), which is equivalent to the timestamp of the most recent item
    251 in the feed. Takes the same arguments as make_recentchanges_rss(). You will most
     252in the feed. Takes the same arguments as make_recentchanges_json(). You will most
    252253likely need this to print a Last-Modified HTTP header so user-agents can determine
    253254whether they need to reload the feed or not.
Note: See TracChangeset for help on using the changeset viewer.